1 /*-
2  * Copyright (C) 2008 Erik Larsson
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 package org.catacombae.storage.fs;
19 
20 /**
21  * @author <a href="http://www.catacombae.org/" target="_top">Erik Larsson</a>
22  */
23 public class WindowsFileAttributes {
24     private static final int FILE_ATTRIBUTE_READONLY = 0x1;
25     private static final int FILE_ATTRIBUTE_HIDDEN = 0x2;
26     private static final int FILE_ATTRIBUTE_SYSTEM = 0x4;
27     private static final int FILE_ATTRIBUTE_DIRECTORY = 0x10;
28     private static final int FILE_ATTRIBUTE_ARCHIVE = 0x20;
29     private static final int FILE_ATTRIBUTE_NORMAL = 0x80;
30     private static final int FILE_ATTRIBUTE_TEMPORARY = 0x100;
31     private static final int FILE_ATTRIBUTE_SPARSE_FILE = 0x200;
32     private static final int FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
33     private static final int FILE_ATTRIBUTE_COMPRESSED = 0x800;
34     private static final int FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
35     private static final int FILE_ATTRIBUTE_OFFLINE = 0x1000;
36     private static final int FILE_ATTRIBUTE_VIRTUAL = 0x10000;
37 
38     private final int attributeDword;
39 
40     /**
41      * Creates a new WindowsFileAttributes from a 32 bit integer holding the
42      * flags as specified in the <code>dwFileAttributes</code> member of
43      * <code>struct BY_HANDLE_FILE_INFORMATION</code> (see
44      * <a href="http://msdn.microsoft.com/en-us/library/aa363788(VS.85).aspx">
45      * MSDN</a>).
46      *
47      * @param iAttributeDword
48      */
WindowsFileAttributes(int iAttributeDword)49     public WindowsFileAttributes(int iAttributeDword) {
50         attributeDword = iAttributeDword;
51     }
52 
53     /**
54      * The file or directory is read-only. Applications can read the file,
55      * but cannot write to it or delete it. If it is a directory,
56      * applications cannot delete it.
57      */
isReadOnly()58     public boolean isReadOnly() {
59         return (attributeDword & FILE_ATTRIBUTE_READONLY) != 0;
60     }
61 
62     /**
63      * The file or directory is hidden. It is not included in an ordinary
64      * directory listing.
65      */
isHidden()66     public boolean isHidden() {
67         return (attributeDword & FILE_ATTRIBUTE_HIDDEN) != 0;
68     }
69 
70     /**
71      * The file or directory is part of the operating system or is used
72      * exclusively by the operating system.
73      */
isSystem()74     public boolean isSystem() {
75         return (attributeDword & FILE_ATTRIBUTE_SYSTEM) != 0;
76     }
77 
78     /** The handle identifies a directory. */
isDirectory()79     public boolean isDirectory() {
80         return (attributeDword & FILE_ATTRIBUTE_DIRECTORY) != 0;
81     }
82 
83     /**
84      * The file or directory is an archive file. Applications use this
85      * attribute to mark files for backup or removal.
86      */
isArchive()87     public boolean isArchive() {
88         return (attributeDword & FILE_ATTRIBUTE_ARCHIVE) != 0;
89     }
90 
91     /**
92      * The file does not have other attributes. This attribute is valid only
93      * if used alone.
94      */
isNormal()95     public boolean isNormal() {
96         return (attributeDword & FILE_ATTRIBUTE_NORMAL) != 0;
97     }
98 
99     /**
100      * The file is being used for temporary storage. File systems avoid
101      * writing data back to mass storage if sufficient cache memory is
102      * available, because often the application deletes the temporary file
103      * after the handle is closed. In that case, the system can entirely
104      * avoid writing the data. Otherwise, the data will be written after the
105      * handle is closed.
106      */
isTemporary()107     public boolean isTemporary() {
108         return (attributeDword & FILE_ATTRIBUTE_TEMPORARY) != 0;
109     }
110 
111     /** The file is a sparse file. */
isSparseFile()112     public boolean isSparseFile() {
113         return (attributeDword & FILE_ATTRIBUTE_SPARSE_FILE) != 0;
114     }
115 
116     /** The file or directory has an associated reparse point. */
isReparsePoint()117     public boolean isReparsePoint() {
118         return (attributeDword & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
119     }
120 
121     /**
122      * The file or directory is compressed. For a file, this means that all
123      * of the data in the file is compressed. For a directory, this means
124      * that compression is the default for newly created files and
125      * subdirectories.
126      */
isCompressed()127     public boolean isCompressed() {
128         return (attributeDword & FILE_ATTRIBUTE_COMPRESSED) != 0;
129     }
130 
131     /**
132      * The file or directory is encrypted. For a file, this means that all
133      * data in the file is encrypted. For a directory, this means that
134      * encryption is the default for newly created files and subdirectories.
135      */
isEncrypted()136     public boolean isEncrypted() {
137         return (attributeDword & FILE_ATTRIBUTE_ENCRYPTED) != 0;
138     }
139 
140     /**
141      * The file data is not available immediately. This attribute indicates
142      * that the file data is physically moved to offline storage. This
143      * attribute is used by Remote Storage, the hierarchical storage
144      * management software. Applications should not arbitrarily change this
145      * attribute.
146      */
isOffline()147     public boolean isOffline() {
148         return (attributeDword & FILE_ATTRIBUTE_OFFLINE) != 0;
149     }
150 
151     /** A file is a virtual file. */
isVirtual()152     public boolean isVirtual() {
153         return (attributeDword & FILE_ATTRIBUTE_VIRTUAL) != 0;
154     }
155 }
156 
157