1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/tools/FileObject.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,161 @@ 1.4 +/* 1.5 + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package javax.tools; 1.30 + 1.31 +import java.io.IOException; 1.32 +import java.io.CharConversionException; 1.33 +import java.io.InputStream; 1.34 +import java.io.OutputStream; 1.35 +import java.io.Reader; 1.36 +import java.io.Writer; 1.37 +import java.nio.CharBuffer; 1.38 +import java.net.URI; 1.39 + 1.40 +/** 1.41 + * File abstraction for tools. In this context, <em>file</em> means 1.42 + * an abstraction of regular files and other sources of data. For 1.43 + * example, a file object can be used to represent regular files, 1.44 + * memory cache, or data in databases. 1.45 + * 1.46 + * <p>All methods in this interface might throw a SecurityException if 1.47 + * a security exception occurs. 1.48 + * 1.49 + * <p>Unless explicitly allowed, all methods in this interface might 1.50 + * throw a NullPointerException if given a {@code null} argument. 1.51 + * 1.52 + * @author Peter von der Ahé 1.53 + * @author Jonathan Gibbons 1.54 + * @since 1.6 1.55 + */ 1.56 +public interface FileObject { 1.57 + 1.58 + /** 1.59 + * Returns a URI identifying this file object. 1.60 + * @return a URI 1.61 + */ 1.62 + URI toUri(); 1.63 + 1.64 + /** 1.65 + * Gets a user-friendly name for this file object. The exact 1.66 + * value returned is not specified but implementations should take 1.67 + * care to preserve names as given by the user. For example, if 1.68 + * the user writes the filename {@code "BobsApp\Test.java"} on 1.69 + * the command line, this method should return {@code 1.70 + * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri} 1.71 + * method might return {@code 1.72 + * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}. 1.73 + * 1.74 + * @return a user-friendly name 1.75 + */ 1.76 + String getName(); 1.77 + 1.78 + /** 1.79 + * Gets an InputStream for this file object. 1.80 + * 1.81 + * @return an InputStream 1.82 + * @throws IllegalStateException if this file object was 1.83 + * opened for writing and does not support reading 1.84 + * @throws UnsupportedOperationException if this kind of file 1.85 + * object does not support byte access 1.86 + * @throws IOException if an I/O error occurred 1.87 + */ 1.88 + InputStream openInputStream() throws IOException; 1.89 + 1.90 + /** 1.91 + * Gets an OutputStream for this file object. 1.92 + * 1.93 + * @return an OutputStream 1.94 + * @throws IllegalStateException if this file object was 1.95 + * opened for reading and does not support writing 1.96 + * @throws UnsupportedOperationException if this kind of 1.97 + * file object does not support byte access 1.98 + * @throws IOException if an I/O error occurred 1.99 + */ 1.100 + OutputStream openOutputStream() throws IOException; 1.101 + 1.102 + /** 1.103 + * Gets a reader for this object. The returned reader will 1.104 + * replace bytes that cannot be decoded with the default 1.105 + * translation character. In addition, the reader may report a 1.106 + * diagnostic unless {@code ignoreEncodingErrors} is true. 1.107 + * 1.108 + * @param ignoreEncodingErrors ignore encoding errors if true 1.109 + * @return a Reader 1.110 + * @throws IllegalStateException if this file object was 1.111 + * opened for writing and does not support reading 1.112 + * @throws UnsupportedOperationException if this kind of 1.113 + * file object does not support character access 1.114 + * @throws IOException if an I/O error occurred 1.115 + */ 1.116 + Reader openReader(boolean ignoreEncodingErrors) throws IOException; 1.117 + 1.118 + /** 1.119 + * Gets the character content of this file object, if available. 1.120 + * Any byte that cannot be decoded will be replaced by the default 1.121 + * translation character. In addition, a diagnostic may be 1.122 + * reported unless {@code ignoreEncodingErrors} is true. 1.123 + * 1.124 + * @param ignoreEncodingErrors ignore encoding errors if true 1.125 + * @return a CharSequence if available; {@code null} otherwise 1.126 + * @throws IllegalStateException if this file object was 1.127 + * opened for writing and does not support reading 1.128 + * @throws UnsupportedOperationException if this kind of 1.129 + * file object does not support character access 1.130 + * @throws IOException if an I/O error occurred 1.131 + */ 1.132 + CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException; 1.133 + 1.134 + /** 1.135 + * Gets a Writer for this file object. 1.136 + * 1.137 + * @return a Writer 1.138 + * @throws IllegalStateException if this file object was 1.139 + * opened for reading and does not support writing 1.140 + * @throws UnsupportedOperationException if this kind of 1.141 + * file object does not support character access 1.142 + * @throws IOException if an I/O error occurred 1.143 + */ 1.144 + Writer openWriter() throws IOException; 1.145 + 1.146 + /** 1.147 + * Gets the time this file object was last modified. The time is 1.148 + * measured in milliseconds since the epoch (00:00:00 GMT, January 1.149 + * 1, 1970). 1.150 + * 1.151 + * @return the time this file object was last modified; or 0 if 1.152 + * the file object does not exist, if an I/O error occurred, or if 1.153 + * the operation is not supported 1.154 + */ 1.155 + long getLastModified(); 1.156 + 1.157 + /** 1.158 + * Deletes this file object. In case of errors, returns false. 1.159 + * @return true if and only if this file object is successfully 1.160 + * deleted; false otherwise 1.161 + */ 1.162 + boolean delete(); 1.163 + 1.164 +}