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.Comparator;
     24 
     25 /**
     26  * Represents one entry in a {@link FsDirectory}.
     27  *
     28  * @author Ewout Prangsma &lt;epr at jnode.org&gt;
     29  * @author Matthias Treydte &lt;waldheinz at gmail.com&gt;
     30  */
     31 public interface FsDirectoryEntry extends FsObject {
     32 
     33     /**
     34      * Compares directory entries alphabetically, with all directories coming
     35      * before all files.
     36      */
     37     public final static Comparator<FsDirectoryEntry> DIRECTORY_ENTRY_COMPARATOR =
     38             new Comparator<FsDirectoryEntry>() {
     39 
     40         @Override
     41         public int compare(FsDirectoryEntry e1, FsDirectoryEntry e2) {
     42             if (e2.isDirectory() == e1.isDirectory()) {
     43                 /* compare names */
     44                 return e1.getName().compareTo(e2.getName());
     45             } else {
     46                 if (e2.isDirectory()) return 1;
     47                 else return -1;
     48             }
     49         }
     50     };
     51 
     52     /**
     53      * Gets the name of this entry.
     54      *
     55      * @return this entrys name
     56      */
     57     public String getName();
     58 
     59     /**
     60      * Gets the last modification time of this entry.
     61      *
     62      * @return the last modification time of the entry as milliseconds
     63      *      since 1970, or {@code 0} if this filesystem does not support
     64      *      getting the last modification time
     65      * @throws IOException if an error occurs retrieving the time stamp
     66      */
     67     public long getLastModified() throws IOException;
     68 
     69     /**
     70      * Returns the time when this entry was created as ms since 1970.
     71      *
     72      * @return the creation time, or 0 if this feature is not supported
     73      * @throws IOException on error retrieving the time stamp
     74      */
     75     public long getCreated() throws IOException;
     76 
     77     /**
     78      * Returns the time when this entry was last accessed as ms since 1970.
     79      *
     80      * @return the last access time, or 0 if this feature is not supported
     81      * @throws IOException on error retrieving the last access time
     82      */
     83     public long getLastAccessed() throws IOException;
     84 
     85     /**
     86      * Is this entry refering to a file?
     87      *
     88      * @return if this entry refers to a file
     89      */
     90     public boolean isFile();
     91 
     92     /**
     93      * Is this entry refering to a (sub-)directory?
     94      *
     95      * @return if this entry refers to a directory
     96      */
     97     public boolean isDirectory();
     98 
     99     /**
    100      * Sets the name of this entry.
    101      *
    102      * @param newName the new name of this entry
    103      * @throws IOException on error setting the new name
    104      */
    105     public void setName(String newName) throws IOException;
    106 
    107     /**
    108      * Sets the last modification time of this entry.
    109      *
    110      * @param lastModified the new last modification time of this entry
    111      * @throws IOException on write error
    112      */
    113     public void setLastModified(long lastModified) throws IOException;
    114 
    115     /**
    116      * Gets the file this entry refers to. This method can only be called if
    117      * {@code isFile} returns {@code true}.
    118      *
    119      * @return the file described by this entry
    120      * @throws IOException on error accessing the file
    121      * @throws UnsupportedOperationException if this entry is a directory
    122      */
    123     public FsFile getFile()
    124             throws IOException, UnsupportedOperationException;
    125 
    126     /**
    127      * Gets the directory this entry refers to. This method can only be called
    128      * if <code>isDirectory</code> returns true.
    129      *
    130      * @return The directory described by this entry
    131      * @throws IOException on read error
    132      * @throws UnsupportedOperationException if this entry is a file
    133      */
    134     public FsDirectory getDirectory()
    135             throws IOException, UnsupportedOperationException;
    136 
    137     /**
    138      * Indicate if the entry has been modified in memory (ie need to be saved)
    139      *
    140      * @return true if the entry needs to be saved
    141      */
    142     public boolean isDirty();
    143 }
    144