duke@1: /* duke@1: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package javax.tools; duke@1: duke@1: import java.io.IOException; duke@1: import java.io.CharConversionException; duke@1: import java.io.InputStream; duke@1: import java.io.OutputStream; duke@1: import java.io.Reader; duke@1: import java.io.Writer; duke@1: import java.nio.CharBuffer; duke@1: import java.net.URI; duke@1: duke@1: /** duke@1: * File abstraction for tools. In this context, file means duke@1: * an abstraction of regular files and other sources of data. For duke@1: * example, a file object can be used to represent regular files, duke@1: * memory cache, or data in databases. duke@1: * duke@1: *

All methods in this interface might throw a SecurityException if duke@1: * a security exception occurs. duke@1: * duke@1: *

Unless explicitly allowed, all methods in this interface might duke@1: * throw a NullPointerException if given a {@code null} argument. duke@1: * duke@1: * @author Peter von der Ahé duke@1: * @author Jonathan Gibbons duke@1: * @since 1.6 duke@1: */ duke@1: public interface FileObject { duke@1: duke@1: /** duke@1: * Returns a URI identifying this file object. duke@1: * @return a URI duke@1: */ duke@1: URI toUri(); duke@1: duke@1: /** duke@1: * Gets a user-friendly name for this file object. The exact duke@1: * value returned is not specified but implementations should take duke@1: * care to preserve names as given by the user. For example, if duke@1: * the user writes the filename {@code "BobsApp\Test.java"} on duke@1: * the command line, this method should return {@code duke@1: * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri} duke@1: * method might return {@code duke@1: * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}. duke@1: * duke@1: * @return a user-friendly name duke@1: */ duke@1: String getName(); duke@1: duke@1: /** duke@1: * Gets an InputStream for this file object. duke@1: * duke@1: * @return an InputStream duke@1: * @throws IllegalStateException if this file object was duke@1: * opened for writing and does not support reading duke@1: * @throws UnsupportedOperationException if this kind of file duke@1: * object does not support byte access duke@1: * @throws IOException if an I/O error occurred duke@1: */ duke@1: InputStream openInputStream() throws IOException; duke@1: duke@1: /** duke@1: * Gets an OutputStream for this file object. duke@1: * duke@1: * @return an OutputStream duke@1: * @throws IllegalStateException if this file object was duke@1: * opened for reading and does not support writing duke@1: * @throws UnsupportedOperationException if this kind of duke@1: * file object does not support byte access duke@1: * @throws IOException if an I/O error occurred duke@1: */ duke@1: OutputStream openOutputStream() throws IOException; duke@1: duke@1: /** duke@1: * Gets a reader for this object. The returned reader will duke@1: * replace bytes that cannot be decoded with the default duke@1: * translation character. In addition, the reader may report a duke@1: * diagnostic unless {@code ignoreEncodingErrors} is true. duke@1: * duke@1: * @param ignoreEncodingErrors ignore encoding errors if true duke@1: * @return a Reader duke@1: * @throws IllegalStateException if this file object was duke@1: * opened for writing and does not support reading duke@1: * @throws UnsupportedOperationException if this kind of duke@1: * file object does not support character access duke@1: * @throws IOException if an I/O error occurred duke@1: */ duke@1: Reader openReader(boolean ignoreEncodingErrors) throws IOException; duke@1: duke@1: /** duke@1: * Gets the character content of this file object, if available. duke@1: * Any byte that cannot be decoded will be replaced by the default duke@1: * translation character. In addition, a diagnostic may be duke@1: * reported unless {@code ignoreEncodingErrors} is true. duke@1: * duke@1: * @param ignoreEncodingErrors ignore encoding errors if true duke@1: * @return a CharSequence if available; {@code null} otherwise duke@1: * @throws IllegalStateException if this file object was duke@1: * opened for writing and does not support reading duke@1: * @throws UnsupportedOperationException if this kind of duke@1: * file object does not support character access duke@1: * @throws IOException if an I/O error occurred duke@1: */ duke@1: CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException; duke@1: duke@1: /** duke@1: * Gets a Writer for this file object. duke@1: * duke@1: * @return a Writer duke@1: * @throws IllegalStateException if this file object was duke@1: * opened for reading and does not support writing duke@1: * @throws UnsupportedOperationException if this kind of duke@1: * file object does not support character access duke@1: * @throws IOException if an I/O error occurred duke@1: */ duke@1: Writer openWriter() throws IOException; duke@1: duke@1: /** duke@1: * Gets the time this file object was last modified. The time is duke@1: * measured in milliseconds since the epoch (00:00:00 GMT, January duke@1: * 1, 1970). duke@1: * duke@1: * @return the time this file object was last modified; or 0 if duke@1: * the file object does not exist, if an I/O error occurred, or if duke@1: * the operation is not supported duke@1: */ duke@1: long getLastModified(); duke@1: duke@1: /** duke@1: * Deletes this file object. In case of errors, returns false. duke@1: * @return true if and only if this file object is successfully duke@1: * deleted; false otherwise duke@1: */ duke@1: boolean delete(); duke@1: duke@1: }