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

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

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