1 /*
2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.tools;
27 
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.io.Reader;
32 import java.io.Writer;
33 import java.net.URI;
34 
35 /**
36  * File abstraction for tools.  In this context, <em>file</em> means
37  * an abstraction of regular files and other sources of data.  For
38  * example, a file object can be used to represent regular files,
39  * memory cache, or data in databases.
40  *
41  * <p>All methods in this interface might throw a SecurityException if
42  * a security exception occurs.
43  *
44  * <p>Unless explicitly allowed, all methods in this interface might
45  * throw a NullPointerException if given a {@code null} argument.
46  *
47  * @author Peter von der Ah&eacute;
48  * @author Jonathan Gibbons
49  * @since 1.6
50  */
51 public interface FileObject {
52 
53     /**
54      * Returns a URI identifying this file object.
55      * @return a URI
56      */
toUri()57     URI toUri();
58 
59     /**
60      * Returns a user-friendly name for this file object.  The exact
61      * value returned is not specified but implementations should take
62      * care to preserve names as given by the user.  For example, if
63      * the user writes the filename {@code "BobsApp\Test.java"} on
64      * the command line, this method should return {@code
65      * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri}
66      * method might return {@code
67      * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}.
68      *
69      * @return a user-friendly name
70      */
getName()71     String getName();
72 
73     /**
74      * Returns an InputStream for this file object.
75      *
76      * @return an InputStream
77      * @throws IllegalStateException if this file object was
78      * opened for writing and does not support reading
79      * @throws UnsupportedOperationException if this kind of file
80      * object does not support byte access
81      * @throws IOException if an I/O error occurred
82      */
openInputStream()83     InputStream openInputStream() throws IOException;
84 
85     /**
86      * Returns an OutputStream for this file object.
87      *
88      * @return an OutputStream
89      * @throws IllegalStateException if this file object was
90      * opened for reading and does not support writing
91      * @throws UnsupportedOperationException if this kind of
92      * file object does not support byte access
93      * @throws IOException if an I/O error occurred
94      */
openOutputStream()95     OutputStream openOutputStream() throws IOException;
96 
97     /**
98      * Returns a reader for this object.  The returned reader will
99      * 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      */
openReader(boolean ignoreEncodingErrors)111     Reader openReader(boolean ignoreEncodingErrors) throws IOException;
112 
113     /**
114      * Returns 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      */
getCharContent(boolean ignoreEncodingErrors)127     CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;
128 
129     /**
130      * Returns 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      */
openWriter()139     Writer openWriter() throws IOException;
140 
141     /**
142      * Returns 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      */
getLastModified()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      */
delete()157     boolean delete();
158 
159 }
160