KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > ntfs > StreamInfo


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.server.ntfs;
18
19 /**
20  * File Stream Information Class
21  * <p>
22  * Contains the details of a file stream.
23  */

24 public class StreamInfo
25 {
26
27     // Constants
28

29     public static final String JavaDoc StreamSeparator = ":";
30
31     // Set stream information flags
32

33     public static final int SetStreamSize = 0x0001;
34     public static final int SetAllocationSize = 0x0002;
35     public static final int SetModifyDate = 0x0004;
36     public static final int SetCreationDate = 0x0008;
37     public static final int SetAccessDate = 0x0010;
38
39     // File path and stream name
40

41     private String JavaDoc m_path;
42     private String JavaDoc m_name;
43
44     // Parent file id and stream id
45

46     private int m_fid;
47     private int m_stid;
48
49     // Stream size/allocation size
50

51     private long m_size;
52     private long m_allocSize;
53
54     // Stream creation, modification and access date/times
55

56     private long m_createDate;
57     private long m_modifyDate;
58     private long m_accessDate;
59
60     // Set stream information setter flags
61

62     private int m_setFlags;
63
64     /**
65      * Default constructor
66      */

67     public StreamInfo()
68     {
69     }
70
71     /**
72      * Constructor
73      *
74      * @param path String
75      */

76     public StreamInfo(String JavaDoc path)
77     {
78
79         // Parse the path to split into path and stream components
80

81         parsePath(path);
82     }
83
84     /**
85      * Constructor
86      *
87      * @param name String
88      * @param fid int
89      * @param stid int
90      */

91     public StreamInfo(String JavaDoc name, int fid, int stid)
92     {
93         m_name = name;
94         m_fid = fid;
95         m_stid = stid;
96     }
97
98     /**
99      * Constructor
100      *
101      * @param name String
102      * @param fid int
103      * @param stid int
104      * @param size long
105      * @param alloc long
106      */

107     public StreamInfo(String JavaDoc name, int fid, int stid, long size, long alloc)
108     {
109         m_name = name;
110         m_fid = fid;
111         m_stid = stid;
112         m_size = size;
113         m_allocSize = alloc;
114     }
115
116     /**
117      * Return the file path
118      *
119      * @return String
120      */

121     public final String JavaDoc getPath()
122     {
123         return m_path;
124     }
125
126     /**
127      * Return the stream name
128      *
129      * @return String
130      */

131     public final String JavaDoc getName()
132     {
133         return m_name;
134     }
135
136     /**
137      * Return the stream file id
138      *
139      * @return int
140      */

141     public final int getFileId()
142     {
143         return m_fid;
144     }
145
146     /**
147      * Return the stream id
148      *
149      * @return int
150      */

151     public final int getStreamId()
152     {
153         return m_stid;
154     }
155
156     /**
157      * Return the streams last access date/time.
158      *
159      * @return long
160      */

161     public long getAccessDateTime()
162     {
163         return m_accessDate;
164     }
165
166     /**
167      * Return the stream creation date/time.
168      *
169      * @return long
170      */

171     public long getCreationDateTime()
172     {
173         return m_createDate;
174     }
175
176     /**
177      * Return the modification date/time
178      *
179      * @return long
180      */

181     public final long getModifyDateTime()
182     {
183         return m_modifyDate;
184     }
185
186     /**
187      * Return the stream size
188      *
189      * @return long
190      */

191     public final long getSize()
192     {
193         return m_size;
194     }
195
196     /**
197      * Return the stream allocation size
198      *
199      * @return long
200      */

201     public final long getAllocationSize()
202     {
203         return m_allocSize;
204     }
205
206     /**
207      * Determine if the last access date/time is available.
208      *
209      * @return boolean
210      */

211     public boolean hasAccessDateTime()
212     {
213         return m_accessDate == 0L ? false : true;
214     }
215
216     /**
217      * Determine if the creation date/time details are available.
218      *
219      * @return boolean
220      */

221     public boolean hasCreationDateTime()
222     {
223         return m_createDate == 0L ? false : true;
224     }
225
226     /**
227      * Determine if the modify date/time details are available.
228      *
229      * @return boolean
230      */

231     public boolean hasModifyDateTime()
232     {
233         return m_modifyDate == 0L ? false : true;
234     }
235
236     /**
237      * Determine if the specified set stream information flags is enabled
238      *
239      * @param setFlag int
240      * @return boolean
241      */

242     public final boolean hasSetFlag(int flag)
243     {
244         if ((m_setFlags & flag) != 0)
245             return true;
246         return false;
247     }
248
249     /**
250      * Return the set stream information flags
251      *
252      * @return int
253      */

254     public final int getSetStreamInformationFlags()
255     {
256         return m_setFlags;
257     }
258
259     /**
260      * Set the path, if it contains the stream name the path will be split into file name and stream
261      * name components.
262      *
263      * @param path String
264      */

265     public final void setPath(String JavaDoc path)
266     {
267         parsePath(path);
268     }
269
270     /**
271      * Set the stream name
272      *
273      * @param name String
274      */

275     public final void setName(String JavaDoc name)
276     {
277         m_name = name;
278     }
279
280     /**
281      * Set the streams last access date/time.
282      *
283      * @param timesec long
284      */

285     public void setAccessDateTime(long timesec)
286     {
287
288         // Create the access date/time
289

290         m_accessDate = timesec;
291     }
292
293     /**
294      * Set the creation date/time for the stream.
295      *
296      * @param timesec long
297      */

298     public void setCreationDateTime(long timesec)
299     {
300
301         // Set the creation date/time
302

303         m_createDate = timesec;
304     }
305
306     /**
307      * Set the modifucation date/time for the stream.
308      *
309      * @param timesec long
310      */

311     public void setModifyDateTime(long timesec)
312     {
313
314         // Set the date/time
315

316         m_modifyDate = timesec;
317     }
318
319     /**
320      * Set the file id
321      *
322      * @param id int
323      */

324     public final void setFileId(int id)
325     {
326         m_fid = id;
327     }
328
329     /**
330      * Set the stream id
331      *
332      * @param id int
333      */

334     public final void setStreamId(int id)
335     {
336         m_stid = id;
337     }
338
339     /**
340      * Set the stream size
341      *
342      * @param size long
343      */

344     public final void setSize(long size)
345     {
346         m_size = size;
347     }
348
349     /**
350      * Set the stream allocation size
351      *
352      * @param alloc long
353      */

354     public final void setAllocationSize(long alloc)
355     {
356         m_allocSize = alloc;
357     }
358
359     /**
360      * Set the set stream information flags to indicated which values are to be set
361      *
362      * @param setFlags int
363      */

364     public final void setStreamInformationFlags(int setFlags)
365     {
366         m_setFlags = setFlags;
367     }
368
369     /**
370      * Parse a path to split into file name and stream name components
371      *
372      * @param path String
373      */

374     protected final void parsePath(String JavaDoc path)
375     {
376
377         // Check if the file name contains a stream name
378

379         int pos = path.indexOf(StreamSeparator);
380         if (pos == -1)
381         {
382             m_path = path;
383             return;
384         }
385
386         // Split the main file name and stream name
387

388         m_path = path.substring(0, pos);
389         m_name = path.substring(pos + 1);
390     }
391
392     /**
393      * Return the stream information as a string
394      *
395      * @return String
396      */

397     public String JavaDoc toString()
398     {
399         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
400
401         str.append("[");
402         str.append(getName());
403         str.append(",");
404         str.append(getFileId());
405         str.append(":");
406         str.append(getStreamId());
407         str.append(",");
408         str.append(getSize());
409         str.append("/");
410         str.append(getAllocationSize());
411         str.append("]");
412
413         return str.toString();
414     }
415 }
416
Popular Tags