Home | History | Annotate | Download | only in fs
      1 /*
      2  * Copyright (C) 2003-2009 JNode.org
      3  *               2009,2010 Matthias Treydte <mt (at) waldheinz.de>
      4  *
      5  * This library is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU Lesser General Public License as published
      7  * by the Free Software Foundation; either version 2.1 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
     13  * License for more details.
     14  *
     15  * You should have received a copy of the GNU Lesser General Public License
     16  * along with this library; If not, write to the Free Software Foundation, Inc.,
     17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     18  */
     19 
     20 package de.waldheinz.fs;
     21 
     22 import java.io.IOException;
     23 import java.util.Iterator;
     24 
     25 /**
     26  * Base class for all {@link FileSystem} directories.
     27  *
     28  * @author Ewout Prangsma &lt; epr at jnode.org&gt;
     29  * @author Matthias Treydte
     30  */
     31 public interface FsDirectory extends Iterable<FsDirectoryEntry>, FsObject {
     32 
     33     /**
     34      * Gets an iterator to iterate over the entries of this directory.
     35      *
     36      * @return the directory iterator
     37      */
     38     @Override
     39     public Iterator<FsDirectoryEntry> iterator();
     40 
     41     /**
     42      * Gets the entry with the given name.
     43      *
     44      * @param name the name of the entry to get
     45      * @return the entry, if it existed
     46      * @throws IOException on error retrieving the entry
     47      */
     48     public FsDirectoryEntry getEntry(String name) throws IOException;
     49 
     50     /**
     51      * Add a new file with a given name to this directory.
     52      *
     53      * @param name the name of the file to add
     54      * @return the entry pointing to the new file
     55      * @throws IOException on error creating the file
     56      */
     57     public FsDirectoryEntry addFile(String name) throws IOException;
     58 
     59     /**
     60      * Add a new (sub-)directory with a given name to this directory.
     61      *
     62      * @param name the name of the sub-directory to add
     63      * @return the entry pointing to the new directory
     64      * @throws IOException on error creating the directory
     65      */
     66     public FsDirectoryEntry addDirectory(String name) throws IOException;
     67 
     68     /**
     69      * Remove the entry with the given name from this directory.
     70      *
     71      * @param name name of the entry to remove
     72      * @throws IOException on error deleting the entry
     73      */
     74     public void remove(String name) throws IOException;
     75 
     76     /**
     77      * Save all dirty (unsaved) data to the device.
     78      *
     79      * @throws IOException on write error
     80      */
     81     public void flush() throws IOException;
     82 
     83 }
     84