001 /*
002 * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.tools;
027
028 import java.io.IOException;
029 import java.io.InputStream;
030 import java.io.OutputStream;
031 import java.io.Reader;
032 import java.io.Writer;
033 import java.net.URI;
034
035 /**
036 * File abstraction for tools. In this context, <em>file</em> means
037 * an abstraction of regular files and other sources of data. For
038 * example, a file object can be used to represent regular files,
039 * memory cache, or data in databases.
040 *
041 * <p>All methods in this interface might throw a SecurityException if
042 * a security exception occurs.
043 *
044 * <p>Unless explicitly allowed, all methods in this interface might
045 * throw a NullPointerException if given a {@code null} argument.
046 *
047 * @author Peter von der Ahé
048 * @author Jonathan Gibbons
049 * @since 1.6
050 */
051 public interface FileObject {
052
053 /**
054 * Returns a URI identifying this file object.
055 * @return a URI
056 */
057 URI toUri();
058
059 /**
060 * Gets a user-friendly name for this file object. The exact
061 * value returned is not specified but implementations should take
062 * care to preserve names as given by the user. For example, if
063 * the user writes the filename {@code "BobsApp\Test.java"} on
064 * the command line, this method should return {@code
065 * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri}
066 * method might return {@code
067 * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}.
068 *
069 * @return a user-friendly name
070 */
071 String getName();
072
073 /**
074 * Gets an InputStream for this file object.
075 *
076 * @return an InputStream
077 * @throws IllegalStateException if this file object was
078 * opened for writing and does not support reading
079 * @throws UnsupportedOperationException if this kind of file
080 * object does not support byte access
081 * @throws IOException if an I/O error occurred
082 */
083 InputStream openInputStream() throws IOException;
084
085 /**
086 * Gets an OutputStream for this file object.
087 *
088 * @return an OutputStream
089 * @throws IllegalStateException if this file object was
090 * opened for reading and does not support writing
091 * @throws UnsupportedOperationException if this kind of
092 * file object does not support byte access
093 * @throws IOException if an I/O error occurred
094 */
095 OutputStream openOutputStream() throws IOException;
096
097 /**
098 * Gets a reader for this object. The returned reader will
099 * replace bytes that cannot be decoded with the default
100 * translation character. In addition, the reader may report a
101 * diagnostic unless {@code ignoreEncodingErrors} is true.
102 *
103 * @param ignoreEncodingErrors ignore encoding errors if true
104 * @return a Reader
105 * @throws IllegalStateException if this file object was
106 * opened for writing and does not support reading
107 * @throws UnsupportedOperationException if this kind of
108 * file object does not support character access
109 * @throws IOException if an I/O error occurred
110 */
111 Reader openReader(boolean ignoreEncodingErrors) throws IOException;
112
113 /**
114 * Gets the character content of this file object, if available.
115 * Any byte that cannot be decoded will be replaced by the default
116 * translation character. In addition, a diagnostic may be
117 * reported unless {@code ignoreEncodingErrors} is true.
118 *
119 * @param ignoreEncodingErrors ignore encoding errors if true
120 * @return a CharSequence if available; {@code null} otherwise
121 * @throws IllegalStateException if this file object was
122 * opened for writing and does not support reading
123 * @throws UnsupportedOperationException if this kind of
124 * file object does not support character access
125 * @throws IOException if an I/O error occurred
126 */
127 CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;
128
129 /**
130 * Gets a Writer for this file object.
131 *
132 * @return a Writer
133 * @throws IllegalStateException if this file object was
134 * opened for reading and does not support writing
135 * @throws UnsupportedOperationException if this kind of
136 * file object does not support character access
137 * @throws IOException if an I/O error occurred
138 */
139 Writer openWriter() throws IOException;
140
141 /**
142 * Gets the time this file object was last modified. The time is
143 * measured in milliseconds since the epoch (00:00:00 GMT, January
144 * 1, 1970).
145 *
146 * @return the time this file object was last modified; or 0 if
147 * the file object does not exist, if an I/O error occurred, or if
148 * the operation is not supported
149 */
150 long getLastModified();
151
152 /**
153 * Deletes this file object. In case of errors, returns false.
154 * @return true if and only if this file object is successfully
155 * deleted; false otherwise
156 */
157 boolean delete();
158
159 }