001: /*=============================================================================
002: * Copyright Texas Instruments 2000-2003. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package oscript.fs;
020:
021: /**
022: * An interface to be implemented by something that can implement file-like
023: * operations. Ie read as a stream, write as a stream.
024: *
025: * @author Rob Clark (rob@ti.com)
026: */
027: public interface AbstractFile {
028: /**
029: * Get an input stream to read from this file.
030: *
031: * @return input stream
032: * @throws IOException if <code>canRead</code> returns <code>true</code>
033: * @see #canRead
034: */
035: public java.io.InputStream getInputStream()
036: throws java.io.IOException;
037:
038: /**
039: * Get an output stream to write to this file.
040: *
041: * @return output stream
042: * @throws IOException if <code>canWrite</code> returns <code>false</code>
043: * @see #canWrite
044: */
045: public java.io.OutputStream getOutputStream(boolean append)
046: throws java.io.IOException;
047:
048: /**
049: * Return the time of last modification. The meaning of these value is not
050: * so important, but the implementation must ensure that a higher value is
051: * returned for the more recent version of a given element. Ie. if at some
052: * point this returns X, an <code>AbstractFile</code> representing the same
053: * "file", but created at a later time, should return X if the file has not
054: * been modified, or >X if the file has been modified.
055: *
056: * @return larger value indicates more recent modification
057: */
058: public long lastModified();
059:
060: /**
061: * Return the length of the file in bytes.
062: */
063: public long length();
064:
065: /**
066: * Is it possible to read from this file.
067: */
068: public boolean canRead();
069:
070: /**
071: * Is it possible to write to this file.
072: */
073: public boolean canWrite();
074:
075: /**
076: * Tests whether this file exists.
077: *
078: * @return <code>true</code> iff the file exists
079: */
080: public boolean exists();
081:
082: /**
083: * Test whether this file is a directory.
084: *
085: * @return <code>true</code> iff this file is a directory
086: */
087: public boolean isDirectory();
088:
089: /**
090: * Test whether this file is a regular file. A file is a regular file if
091: * it is not a directory.
092: *
093: * @return <code>true</code> iff this file is a regular file.
094: */
095: public boolean isFile();
096:
097: /**
098: * Create a new empty file, if it does not yet exist.
099: *
100: * @return <code>true</code> iff the file does not exist and was successfully
101: * created.
102: * @throws IOException if error
103: */
104: public boolean createNewFile() throws java.io.IOException;
105:
106: /**
107: * Update the timestamp on this file to the current time.
108: *
109: * @throws IOException if error
110: */
111: public void touch() throws java.io.IOException;
112:
113: /**
114: * Delete this file. If this file is a directory, then the directory must
115: * be empty.
116: *
117: * @return <code>true<code> iff the directory is successfully deleted.
118: * @throws IOException if error
119: */
120: public boolean delete() throws java.io.IOException;
121:
122: /**
123: * If this file does not exist, create it as a directory.
124: *
125: * @return <code>true</code> iff directory successfully created
126: */
127: public boolean mkdir() throws java.io.IOException;
128:
129: /**
130: * If this file does not exist, create it as a directory. All necessary
131: * parent directories are also created. If this operation fails, it may
132: * have successfully created some or all of the parent directories.
133: *
134: * @return <code>true</code> iff directory successfully created
135: */
136: public boolean mkdirs() throws java.io.IOException;
137:
138: /**
139: * Get the file path, which globally identifies the file.
140: *
141: * @return a unique string
142: * @see #getName
143: */
144: public String getPath();
145:
146: /**
147: * Get the name of this file, which is the last component of the complete path.
148: *
149: * @return the file name
150: * @see #getPath
151: */
152: public String getName();
153:
154: /**
155: * Get the extension, which indicates the type of file. Usually the extension
156: * is part of the filename, ie. if the extension was <i>os</i>, the filename
157: * would end with <i>.os</i>.
158: *
159: * @return a string indicating the type of file
160: */
161: public String getExtension();
162: }
163:
164: /*
165: * Local Variables:
166: * tab-width: 2
167: * indent-tabs-mode: nil
168: * mode: java
169: * c-indentation-style: java
170: * c-basic-offset: 2
171: * eval: (c-set-offset 'substatement-open '0)
172: * eval: (c-set-offset 'case-label '+)
173: * eval: (c-set-offset 'inclass '+)
174: * eval: (c-set-offset 'inline-open '0)
175: * End:
176: */
|