KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > AbstractFileSystem


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.filesystems;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.ObjectInputStream JavaDoc;
26 import java.io.ObjectOutputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.Serializable JavaDoc;
29 import java.lang.ref.Reference JavaDoc;
30 import java.lang.ref.WeakReference JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.Enumeration JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import org.openide.util.Enumerations;
36 import org.openide.util.Lookup;
37 import org.openide.util.NbCollections;
38 import org.openide.util.SharedClassObject;
39 import org.openide.util.actions.SystemAction;
40
41 /**
42  * This convenience implementation does much of the hard work of
43  * <code>FileSystem</code> and is generally more pleasant to create
44  * subclasses of.
45  *
46  * <p>It caches information about the filesystem in memory and periodically refreshes its content. Many other
47  * operations are performed in a safer manner so as to reuse experience of NetBeans developers; should be
48  * substantially simpler to subclass than {@link FileSystem} itself.
49  *
50  * <p>Besides what is mentioned here, the <code>AbstractFileSystem</code> subclass be configurable as a JavaBean
51  * (e.g. server address, prefix, whatever it needs).
52  *
53  * <p>First of all, you need not separately implement a {@link FileObject} - this is taken care of for you. You
54  * need only provide some information about how essential actions should be carried out.
55  *
56  * <p>You should implement {@link #getDisplayName()} to set the display name.
57  *
58  * <p>You may cause the filesystem to automatically refresh itself at periodic intervals, in case it is not
59  * possible to be notified of changes directly. To do so, call {@link #setRefreshTime(int)}, e.g. from the
60  * constructor.
61  *
62  * <p>{@link #refreshRoot()} must be called if the filesystem supports changing of its root directory (as the
63  * local filesystem does, for example).
64  *
65  * <p>Most of the meat of the implementation is provided by setting appropriate values for four protected
66  * variables, which should be initialized in the constructor; each represents an implementation of a separate
67  * interface handling one aspect of the filesystem.
68  *
69  * <h4>List member</h4>
70  *
71  * The variable {@link #list} should contain an implementation of {@link AbstractFileSystem.List}. This only
72  * specifies a way of accessing the list of children in a folder.
73  *
74  * <h4>Info member</h4>
75  *
76  * {@link #info} contains an {@link AbstractFileSystem.Info} which provides basic file statistics.
77  *
78  * <p>It also specifies the raw implementation of two basic types of actions: getting input and output streams
79  * for the file; and locking and unlocking it physically (optional and not to be confused with locking within
80  * NetBeans).
81  *
82  * <h4>Change member</h4>
83  *
84  * {@link #change} is an {@link AbstractFileSystem.Change} which provides the interface to create new folders
85  * and files; delete them; and rename them (within the same directory).
86  *
87  * <h4>Attribute member</h4>
88  *
89  * {@link #attr} is an {@link AbstractFileSystem.Attr} allowing NetBeans to read and write serializable
90  * attributes (meta-information) to be associated with the file. Such attributes are not much used any more, but
91  * they are occasionally.
92  *
93  * <p>There is a default implementation in {@link DefaultAttributes} which stores attributes in a file called
94  * <code>.nbattrs</code> in each folder for which a file has some attributes, using XML augmented by Java
95  * serialization, though the regular filesystems in NetBeans now instead store all attributes globally in
96  * <code>$userdir/var/attributes.xml</code>. If you do use <code>DefaultAttributes</code>, use it not only for
97  * {@link #attr} but also for {@link #list} (passing in a separate private {@link AbstractFileSystem.List}
98  * implementation to its constructor) in order to filter the <code>.nbattrs</code> files from view.
99  */

100 public abstract class AbstractFileSystem extends FileSystem {
101     /** generated Serialized Version UID */
102     static final long serialVersionUID = -3345098214331282438L;
103
104     /** system actions for this FS if it has refreshTime != 0 */
105     private static SystemAction[] SYSTEM_ACTIONS;
106
107     /** system actions for this FS */
108     private static final SystemAction[] NO_SYSTEM_ACTIONS = new SystemAction[] { };
109
110     /** cached last value of Enumeration which holds resource name (enumeration like StringTokenizer)*/
111     static transient private PathElements lastEnum;
112
113     /** root object for the filesystem */
114     private transient AbstractFileObject root;
115
116     /** refresher */
117     private transient RefreshRequest refresher;
118
119     /** Provider of hierarchy of files. */
120     protected List list;
121
122     /** Methods for modification of files. */
123     protected Change change;
124
125     /** Methods for moving of files. This field can be left null if the filesystem
126     * does not require special handling handling of FileObject.move and is satified
127     * with the default implementation.
128     */

129     protected Transfer transfer;
130
131     /** Methods for obtaining information about files. */
132     protected Info info;
133
134     /** Handling of attributes for files. */
135     protected Attr attr;
136
137     /**
138      * Actually implements contract of FileSystem.refresh().
139      */

140     public void refresh(boolean expected) {
141         for (FileObject fo : NbCollections.iterable(getAbstractRoot().existingSubFiles(true))) {
142             fo.refresh(expected);
143         }
144     }
145
146     /* Provides a name for the system that can be presented to the user.
147     * @return user presentable name of the filesystem
148     */

149     public abstract String JavaDoc getDisplayName();
150
151     /* Getter for root folder in the filesystem.
152     *
153     * @return root folder of whole filesystem
154     */

155     public FileObject getRoot() {
156         return getAbstractRoot();
157     }
158
159     /* Finds file when its name is provided.
160     *
161     * @param aPackage package name where each package is separated by a dot
162     * @param name name of the file (without dots) or <CODE>null</CODE> if
163     * one want to obtain name of package and not file in it
164     * @param ext extension of the file or <CODE>null</CODE> if one needs
165     * package and not file name
166     *
167     * @warning when one of name or ext is <CODE>null</CODE> then name and
168     * ext should be ignored and scan should look only for a package
169     *
170     * @return FileObject that represents file with given name or
171     * <CODE>null</CODE> if the file does not exist
172     */

173     @Deprecated JavaDoc
174     public FileObject find(String JavaDoc aPackage, String JavaDoc name, String JavaDoc ext) {
175         // create enumeration of name to look for
176
Enumeration JavaDoc<String JavaDoc> st = NbCollections.checkedEnumerationByFilter(new StringTokenizer JavaDoc(aPackage, "."), String JavaDoc.class, true); // NOI18N
177

178         if ((name == null) || (ext == null)) {
179             // search for folder, return the object only if it is folder
180
FileObject fo = getAbstractRoot().find(st);
181
182             return ((fo != null) && fo.isFolder()) ? fo : null;
183         } else {
184             Enumeration JavaDoc<String JavaDoc> en = Enumerations.concat(st, Enumerations.singleton(name + '.' + ext));
185
186             // tries to find it (can return null)
187
return getAbstractRoot().find(en);
188         }
189     }
190
191     /* Finds file when its resource name is given.
192     * The name has the usual format for the {@link ClassLoader#getResource(String)}
193     * method. So it may consist of "package1/package2/filename.ext".
194     * If there is no package, it may consist only of "filename.ext".
195     *
196     * @param name resource name
197     *
198     * @return FileObject that represents file with given name or
199     * <CODE>null</CODE> if the file does not exist
200     */

201     public FileObject findResource(String JavaDoc name) {
202         if (name.length() == 0) {
203             return getAbstractRoot();
204         }
205
206         /**Next piece of code is preformance enhancement; lastEnum = last value cache;
207          PathElements is StringTokenizer wrapper that caches individual elements*/

208         PathElements local = lastEnum;
209
210         if ((local == null) || !local.getOriginalName().equals(name)) {
211             local = new PathElements(name);
212             lastEnum = local;
213         }
214
215         return getAbstractRoot().find(local.getEnumeration());
216     }
217
218     /** Creates Reference. In FileSystem, which subclasses AbstractFileSystem, you can overload method
219     * createReference(FileObject fo) to achieve another type of Reference (weak, strong etc.)
220     * @param fo is FileObject. It`s reference yourequire to get.
221     * @return Reference to FileObject
222     */

223     protected <T extends FileObject> Reference JavaDoc<T> createReference(T fo) {
224         return (new WeakReference JavaDoc<T>(fo));
225     }
226
227     /** This method allows to find Reference to resourceName
228     * @param resourceName is name of resource
229     * @return Reference to resourceName
230     */

231     protected final Reference JavaDoc<? extends FileObject> findReference(String JavaDoc resourceName) {
232         if (resourceName.length() == 0) {
233             return null;
234         } else {
235             Enumeration JavaDoc<String JavaDoc> tok = NbCollections.checkedEnumerationByFilter(new StringTokenizer JavaDoc(resourceName, "/"), String JavaDoc.class, true); // NOI18N
236

237             return getAbstractRoot().findRefIfExists(tok);
238         }
239     }
240
241     /*
242     * @return true if RefreshAction should be enabled
243     */

244     boolean isEnabledRefreshFolder() {
245         return (refresher != null);
246     }
247
248     /* Action for this filesystem.
249     *
250     * @return refresh action
251     */

252     public SystemAction[] getActions() {
253         if (!isEnabledRefreshFolder()) {
254             return NO_SYSTEM_ACTIONS;
255         } else {
256             if (SYSTEM_ACTIONS == null) {
257                 try {
258                     ClassLoader JavaDoc l = Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
259
260                     if (l == null) {
261                         l = getClass().getClassLoader();
262                     }
263
264                     Class JavaDoc<?> c = Class.forName("org.openide.actions.FileSystemRefreshAction", true, l); // NOI18N
265
SystemAction ra = SharedClassObject.findObject(c.asSubclass(SystemAction.class), true);
266
267                     // initialize the SYSTEM_ACTIONS
268
SYSTEM_ACTIONS = new SystemAction[] { ra };
269                 } catch (Exception JavaDoc ex) {
270                     // ok, we are probably running in standalone mode and
271
// classes needed to initialize the RefreshAction are
272
// not available
273
SYSTEM_ACTIONS = NO_SYSTEM_ACTIONS;
274                 }
275             }
276
277             return SYSTEM_ACTIONS;
278         }
279     }
280
281     /** Set the number of milliseconds between automatic
282     * refreshes of the directory structure.
283     *
284     * @param ms number of milliseconds between two refreshes; if <code><= 0</code> then refreshing is disabled
285     */

286     protected synchronized final void setRefreshTime(int ms) {
287         if (refresher != null) {
288             refresher.stop();
289         }
290
291         if ((ms <= 0) || (System.getProperty("netbeans.debug.heap") != null)) {
292             refresher = null;
293         } else {
294             refresher = new RefreshRequest(this, ms);
295         }
296     }
297
298     /** Get the number of milliseconds between automatic
299     * refreshes of the directory structure.
300     * By default, automatic refreshing is disabled.
301     * @return the number of milliseconds, or <code>0</code> if refreshing is disabled
302     */

303     protected final int getRefreshTime() {
304         RefreshRequest r = refresher;
305
306         return (r == null) ? 0 : r.getRefreshTime();
307     }
308
309     /** Instruct the filesystem
310     * that the root should change.
311     * A fresh root is created. Subclasses that support root changes should use this.
312     *
313     * @return the new root
314     */

315     final synchronized AbstractFileObject refreshRootImpl() {
316         if (root != null) {
317             root.validFlag = false;
318         }
319
320         root = createFileObject(null, ""); // NOI18N
321

322         return root;
323     }
324
325     /** Instruct the filesystem
326     * that the root should change.
327     * A fresh root is created. Subclasses that support root changes should use this.
328     *
329     * @return the new root
330     */

331     protected final FileObject refreshRoot() {
332         return refreshRootImpl();
333     }
334
335     /** Allows subclasses to fire that a change occured in a
336     * file or folder. The change can be "expected" when it is
337     * a result of an user action and the user knows that such
338     * change should occur.
339     *
340     * @param name resource name of the file where the change occured
341     * @param expected true if the user initiated change and expects it
342     */

343     protected final void refreshResource(String JavaDoc name, boolean expected) {
344         AbstractFileObject fo = (AbstractFileObject) findResourceIfExists(name);
345
346         if (fo != null) {
347             // refresh and behave like the changes is expected
348
fo.refresh(null, null, true, expected);
349         }
350     }
351
352     /**
353      * For the FileObject specified as parameter, returns the recursive enumeration
354      * of existing children fileobjects (both folders and data). It doesn't create
355      * any new FileObject instances. Direct children are at the begining of the enumeration.
356      * @param fo the starting point for the recursive fileobject search
357      * @return enumeration of currently existing fileobjects.
358      */

359     protected final Enumeration JavaDoc<? extends FileObject> existingFileObjects(FileObject fo) {
360         return existingFileObjects((AbstractFolder) fo);
361     }
362
363     final Enumeration JavaDoc<? extends FileObject> existingFileObjects(AbstractFolder fo) {
364         class OnlyValidAndDeep implements org.openide.util.Enumerations.Processor<Reference JavaDoc<AbstractFolder>,FileObject> {
365             public FileObject process(Reference JavaDoc<AbstractFolder> obj, Collection JavaDoc<Reference JavaDoc<AbstractFolder>> toAdd) {
366                 AbstractFolder file = obj.get();
367
368                 if (file != null) {
369                     AbstractFolder[] arr = file.subfiles();
370
371                     // make the array weak
372
for (int i = 0; i < arr.length; i++) {
373                         toAdd.add(new WeakReference JavaDoc<AbstractFolder>(arr[i]));
374                     }
375
376                     return file.isValid() ? file : null;
377                 }
378
379                 return null;
380             }
381         }
382
383         Reference JavaDoc<AbstractFolder> ref = new WeakReference JavaDoc<AbstractFolder>(fo);
384         Enumeration JavaDoc<Reference JavaDoc<AbstractFolder>> singleEn = org.openide.util.Enumerations.<Reference JavaDoc<AbstractFolder>>singleton(ref);
385         return org.openide.util.Enumerations.removeNulls(
386             org.openide.util.Enumerations.queue(singleEn, new OnlyValidAndDeep())
387         );
388     }
389
390
391     /**
392     * @return if value of lastModified should be cached
393     */

394     boolean isLastModifiedCacheEnabled() {
395         return true;
396     }
397
398     /* Finds file when its resource name is given.
399     * The name has the usual format for the {@link ClassLoader#getResource(String)}
400     * method. So it may consist of "package1/package2/filename.ext".
401     * If there is no package, it may consist only of "filename.ext".
402     *
403     * @param name resource name
404     *
405     * @return FileObject that represents file with given name or
406     * <CODE>null</CODE> if the file does not exist
407     */

408     private FileObject findResourceIfExists(String JavaDoc name) {
409         if (name.length() == 0) {
410             return getAbstractRoot();
411         } else {
412             Enumeration JavaDoc<String JavaDoc> tok = NbCollections.checkedEnumerationByFilter(new StringTokenizer JavaDoc(name, "/"), String JavaDoc.class, true); // NOI18N
413

414             return getAbstractRoot().findIfExists(tok);
415         }
416     }
417
418     /** Hooking method to allow MultiFileSystem to be informed when a new
419     * file object is created. This is the only method that creates AbstractFileObjects.
420     *
421     * @param parent parent object
422     * @param name of the object
423     */

424     AbstractFileObject createFileObject(AbstractFileObject parent, String JavaDoc name) {
425         return new AbstractFileObject(this, parent, name);
426     }
427
428     /**
429      * Creates root object for the fs.
430      */

431     final AbstractFileObject getAbstractRoot() {
432         synchronized (this) {
433             if (root == null) {
434                 return refreshRootImpl();
435             }
436         }
437
438         return root;
439     }
440
441     /** Writes the common fields and the state of refresher.
442     */

443     private void writeObject(ObjectOutputStream JavaDoc oos) throws IOException JavaDoc {
444         ObjectOutputStream.PutField JavaDoc fields = oos.putFields();
445
446         fields.put("change", change); // NOI18N
447
fields.put("info", info); // NOI18N
448
fields.put("attr", attr); // NOI18N
449
fields.put("list", list); // NOI18N
450
fields.put("transfer", transfer); // NOI18N
451
oos.writeFields();
452
453         oos.writeInt(getRefreshTime());
454     }
455
456     /** Reads common fields and state of refresher.
457     */

458     private void readObject(ObjectInputStream JavaDoc ois) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
459         ObjectInputStream.GetField JavaDoc fields = ois.readFields();
460
461         Object JavaDoc o1 = readImpl("change", fields); // change // NOI18N
462
Object JavaDoc o2 = readImpl("info", fields); // info // NOI18N
463
Object JavaDoc o3 = readImpl("attr", fields); // attr // NOI18N
464
Object JavaDoc o4 = readImpl("list", fields); // list // NOI18N
465
Object JavaDoc o5 = readImpl("transfer", fields); // transfer // NOI18N
466

467         change = (Change) o1;
468         info = (Info) o2;
469         attr = (Attr) o3;
470         list = (List) o4;
471         transfer = (Transfer) o5;
472
473         setRefreshTime(ois.readInt());
474     }
475
476     //
477
// Backward compatibility methods
478
//
479

480     /** Reads object from input stream, if it is
481     * LocalFileSystem or JarFileSystem then replaces the object
482     * by its Impl.
483     */

484     static Object JavaDoc readImpl(String JavaDoc name, ObjectInputStream.GetField JavaDoc fields)
485     throws ClassNotFoundException JavaDoc, IOException JavaDoc {
486         Object JavaDoc o = fields.get(name, null);
487
488         if (o instanceof LocalFileSystem) {
489             return new LocalFileSystem.Impl((LocalFileSystem) o);
490         } else if (o instanceof JarFileSystem) {
491             return new JarFileSystem.Impl((JarFileSystem) o);
492         }
493
494         return o;
495     }
496
497     /**
498      * This method is called from AbstractFileObject.isVirtual. Tests if file
499      * really exists or is missing. Some operation on it may be restricted if returns true.
500      * @param name of the file
501      * @return true indicates that the file is missing.
502      * @since 1.9
503      */

504     protected boolean checkVirtual(String JavaDoc name) {
505         return false;
506     }
507
508     /** Tests if this file can be written to.
509      * @param name resource name
510      * @return true if this file can be written, false if not.
511      * @since 3.31
512      */

513     protected boolean canWrite(String JavaDoc name) {
514         AbstractFileObject afo = (AbstractFileObject) this.findResource(name);
515
516         return (afo != null) ? afo.superCanWrite() : false;
517     }
518
519     /** Tests if this file can be read.
520      * @param name resource name
521      * @return true if this file can be read, false if not.
522      * @since 3.31
523      */

524     protected boolean canRead(String JavaDoc name) {
525         AbstractFileObject afo = (AbstractFileObject) this.findResource(name);
526
527         return (afo != null) ? afo.superCanRead() : false;
528     }
529
530     /** Mark the file as being important or unimportant.
531     * @param name the file to mark
532     * @param important true indicates that file is important, false conversely
533     * file is unimportant.
534     * @since 1.9
535     */

536     protected void markImportant(String JavaDoc name, boolean important) {
537         if (!important && (info != null)) {
538             info.markUnimportant(name);
539         }
540     }
541
542     /** Provides access to the hierarchy of resources.
543     */

544     public interface List extends Serializable JavaDoc {
545         /** @deprecated Only public by accident. */
546         @Deprecated JavaDoc
547         /* public static final */ long serialVersionUID = -6242105832891012528L;
548
549         /** Get a list of children files for a given folder.
550         *
551         * @param f the folder, by name; e.g. <code>top/next/afterthat</code>
552         * @return a list of children of the folder, as <code>file.ext</code> (no path)
553         * the array can contain <code>null</code> values that will be ignored
554         */

555         public String JavaDoc[] children(String JavaDoc f);
556     }
557
558     /** Controls modification of files.
559     */

560     public interface Change extends Serializable JavaDoc {
561         /** @deprecated Only public by accident. */
562         @Deprecated JavaDoc
563         /* public static final */ long serialVersionUID = -5841597109944924596L;
564
565         /** Create new folder.
566         * @param name full name of new folder, e.g. <code>topfolder/newfolder</code>
567         * @throws IOException if the operation fails
568         */

569         public void createFolder(String JavaDoc name) throws IOException JavaDoc;
570
571         /** Create new data file.
572         *
573         * @param name full name of the file, e.g. <code>path/from/root/filename.ext</code>
574         *
575         * @exception IOException if the file cannot be created (e.g. already exists)
576         */

577         public void createData(String JavaDoc name) throws IOException JavaDoc;
578
579         /** Rename a file.
580         *
581         * @param oldName old name of the file; fully qualified
582         * @param newName new name of the file; fully qualified
583         * @throws IOException if it could not be renamed
584         */

585         public void rename(String JavaDoc oldName, String JavaDoc newName)
586         throws IOException JavaDoc;
587
588         /** Delete a file.
589         *
590         * @param name name of file; fully qualified
591         * @exception IOException if the file could not be deleted
592         */

593         public void delete(String JavaDoc name) throws IOException JavaDoc;
594     }
595
596     /** Controls on moving of files. This is additional interface to
597     * allow filesystem that require special handling of move to implement
598     * it in different way then is the default one.
599     */

600     public interface Transfer extends Serializable JavaDoc {
601         /** @deprecated Only public by accident. */
602         @Deprecated JavaDoc
603         /* public static final */ long serialVersionUID = -8945397853892302838L;
604
605         /** Move a file.
606         *
607         * @param name of the file on current filesystem
608         * @param target move implementation
609         * @param targetName of target file
610         * @exception IOException if the move fails
611         * @return false if the method is not able to handle the request and
612         * default implementation should be used instead
613         */

614         public boolean move(String JavaDoc name, Transfer target, String JavaDoc targetName)
615         throws IOException JavaDoc;
616
617         /** Copy a file.
618         *
619         * @param name of the file on current filesystem
620         * @param target target transfer implementation
621         * @param targetName name of target file
622         * @exception IOException if the copy fails
623         * @return false if the method is not able to handle the request and
624         * default implementation should be used instead
625         */

626         public boolean copy(String JavaDoc name, Transfer target, String JavaDoc targetName)
627         throws IOException JavaDoc;
628     }
629
630     /** Information about files.
631     */

632     public interface Info extends Serializable JavaDoc {
633         /** @deprecated Only public by accident. */
634         @Deprecated JavaDoc
635         /* public static final */ long serialVersionUID = -2438286177948307985L;
636
637         /**
638         * Get last modification time.
639         * @param name the file to test
640         * @return the date of last modification
641         */

642         public Date JavaDoc lastModified(String JavaDoc name);
643
644         /** Test if the file is a folder or contains data.
645         * @param name name of the file
646         * @return <code>true</code> if the file is folder, <code>false</code> if it is data
647         */

648         public boolean folder(String JavaDoc name);
649
650         /** Test whether this file can be written to or not.
651         * @param name the file to test
652         * @return <CODE>true</CODE> if the file is read-only
653         */

654         public boolean readOnly(String JavaDoc name);
655
656         /** Get the MIME type of the file. If filesystem has no special support
657         * for MIME types then can simply return null. FileSystem can register
658         * MIME types for a well-known extensions: FileUtil.setMIMEType(String ext, String mimeType)
659         * or together with filesystem supply some resolvers subclassed from MIMEResolver.
660         *
661         * @param name the file to test
662         * @return the MIME type textual representation (e.g. <code>"text/plain"</code>)
663         * or null if no special support for recognizing MIME is implemented.
664          */

665         public String JavaDoc mimeType(String JavaDoc name);
666
667         /** Get the size of the file.
668         *
669         * @param name the file to test
670         * @return the size of the file in bytes, or zero if the file does not contain data (does not
671         * exist or is a folder).
672         */

673         public long size(String JavaDoc name);
674
675         /** Get input stream.
676         *
677         * @param name the file to test
678         * @return an input stream to read the contents of this file
679         * @exception FileNotFoundException if the file does not exist or is invalid
680         */

681         public InputStream JavaDoc inputStream(String JavaDoc name) throws FileNotFoundException JavaDoc;
682
683         /** Get output stream.
684         *
685         * @param name the file to test
686         * @return output stream to overwrite the contents of this file
687         * @exception IOException if an error occurs (the file is invalid, etc.)
688         */

689         public OutputStream JavaDoc outputStream(String JavaDoc name) throws IOException JavaDoc;
690
691         /** Lock the file.
692         * May do nothing if the underlying storage does not support locking.
693         * This does not affect locking using {@link FileLock} within NetBeans, however.
694         * @param name name of the file
695         * @throws FileAlreadyLockedException if the file is already locked
696         */

697         public void lock(String JavaDoc name) throws IOException JavaDoc;
698
699         /** Unlock the file.
700         * @param name name of the file
701         */

702         public void unlock(String JavaDoc name);
703
704         /** Mark the file as being unimportant.
705          * If not called, the file is assumed to be important.
706          * <em>Deprecated</em> and new implementations need not do anything.
707          * @param name the file to mark
708          */

709         public void markUnimportant(String JavaDoc name);
710     }
711
712     /** Handle attributes of files.
713     */

714     public interface Attr extends Serializable JavaDoc {
715         /** @deprecated Only public by accident. */
716         @Deprecated JavaDoc
717         /* public static final */ long serialVersionUID = 5978845941846736946L;
718
719         /** Get the file attribute with the specified name.
720         * @param name the file
721         * @param attrName name of the attribute
722         * @return appropriate (serializable) value or <CODE>null</CODE> if the attribute is unset (or could not be properly restored for some reason)
723         */

724         public Object JavaDoc readAttribute(String JavaDoc name, String JavaDoc attrName);
725
726         /** Set the file attribute with the specified name.
727         * @param name the file
728         * @param attrName name of the attribute
729         * @param value new value or <code>null</code> to clear the attribute. Must be serializable, although particular filesystems may or may not use serialization to store attribute values.
730         * @exception IOException if the attribute cannot be set. If serialization is used to store it, this may in fact be a subclass such as {@link NotSerializableException}.
731         */

732         public void writeAttribute(String JavaDoc name, String JavaDoc attrName, Object JavaDoc value)
733         throws IOException JavaDoc;
734
735         /** Get all file attribute names for the file.
736         * @param name the file
737         * @return enumeration of keys (as strings)
738         */

739         public Enumeration JavaDoc<String JavaDoc> attributes(String JavaDoc name);
740
741         /** Called when a file is renamed, to appropriately update its attributes.
742         * @param oldName old name of the file
743         * @param newName new name of the file
744         */

745         public void renameAttributes(String JavaDoc oldName, String JavaDoc newName);
746
747         /** Called when a file is deleted, to also delete its attributes.
748         *
749         * @param name name of the file
750         */

751         public void deleteAttributes(String JavaDoc name);
752     }
753 }
754
Popular Tags