src/share/classes/javax/tools/FileObject.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 119
1e83972f53fb
permissions
-rw-r--r--

Initial load

duke@1 1 /*
duke@1 2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package javax.tools;
duke@1 27
duke@1 28 import java.io.IOException;
duke@1 29 import java.io.CharConversionException;
duke@1 30 import java.io.InputStream;
duke@1 31 import java.io.OutputStream;
duke@1 32 import java.io.Reader;
duke@1 33 import java.io.Writer;
duke@1 34 import java.nio.CharBuffer;
duke@1 35 import java.net.URI;
duke@1 36
duke@1 37 /**
duke@1 38 * File abstraction for tools. In this context, <em>file</em> means
duke@1 39 * an abstraction of regular files and other sources of data. For
duke@1 40 * example, a file object can be used to represent regular files,
duke@1 41 * memory cache, or data in databases.
duke@1 42 *
duke@1 43 * <p>All methods in this interface might throw a SecurityException if
duke@1 44 * a security exception occurs.
duke@1 45 *
duke@1 46 * <p>Unless explicitly allowed, all methods in this interface might
duke@1 47 * throw a NullPointerException if given a {@code null} argument.
duke@1 48 *
duke@1 49 * @author Peter von der Ah&eacute;
duke@1 50 * @author Jonathan Gibbons
duke@1 51 * @since 1.6
duke@1 52 */
duke@1 53 public interface FileObject {
duke@1 54
duke@1 55 /**
duke@1 56 * Returns a URI identifying this file object.
duke@1 57 * @return a URI
duke@1 58 */
duke@1 59 URI toUri();
duke@1 60
duke@1 61 /**
duke@1 62 * Gets a user-friendly name for this file object. The exact
duke@1 63 * value returned is not specified but implementations should take
duke@1 64 * care to preserve names as given by the user. For example, if
duke@1 65 * the user writes the filename {@code "BobsApp\Test.java"} on
duke@1 66 * the command line, this method should return {@code
duke@1 67 * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri}
duke@1 68 * method might return {@code
duke@1 69 * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}.
duke@1 70 *
duke@1 71 * @return a user-friendly name
duke@1 72 */
duke@1 73 String getName();
duke@1 74
duke@1 75 /**
duke@1 76 * Gets an InputStream for this file object.
duke@1 77 *
duke@1 78 * @return an InputStream
duke@1 79 * @throws IllegalStateException if this file object was
duke@1 80 * opened for writing and does not support reading
duke@1 81 * @throws UnsupportedOperationException if this kind of file
duke@1 82 * object does not support byte access
duke@1 83 * @throws IOException if an I/O error occurred
duke@1 84 */
duke@1 85 InputStream openInputStream() throws IOException;
duke@1 86
duke@1 87 /**
duke@1 88 * Gets an OutputStream for this file object.
duke@1 89 *
duke@1 90 * @return an OutputStream
duke@1 91 * @throws IllegalStateException if this file object was
duke@1 92 * opened for reading and does not support writing
duke@1 93 * @throws UnsupportedOperationException if this kind of
duke@1 94 * file object does not support byte access
duke@1 95 * @throws IOException if an I/O error occurred
duke@1 96 */
duke@1 97 OutputStream openOutputStream() throws IOException;
duke@1 98
duke@1 99 /**
duke@1 100 * Gets a reader for this object. The returned reader will
duke@1 101 * replace bytes that cannot be decoded with the default
duke@1 102 * translation character. In addition, the reader may report a
duke@1 103 * diagnostic unless {@code ignoreEncodingErrors} is true.
duke@1 104 *
duke@1 105 * @param ignoreEncodingErrors ignore encoding errors if true
duke@1 106 * @return a Reader
duke@1 107 * @throws IllegalStateException if this file object was
duke@1 108 * opened for writing and does not support reading
duke@1 109 * @throws UnsupportedOperationException if this kind of
duke@1 110 * file object does not support character access
duke@1 111 * @throws IOException if an I/O error occurred
duke@1 112 */
duke@1 113 Reader openReader(boolean ignoreEncodingErrors) throws IOException;
duke@1 114
duke@1 115 /**
duke@1 116 * Gets the character content of this file object, if available.
duke@1 117 * Any byte that cannot be decoded will be replaced by the default
duke@1 118 * translation character. In addition, a diagnostic may be
duke@1 119 * reported unless {@code ignoreEncodingErrors} is true.
duke@1 120 *
duke@1 121 * @param ignoreEncodingErrors ignore encoding errors if true
duke@1 122 * @return a CharSequence if available; {@code null} otherwise
duke@1 123 * @throws IllegalStateException if this file object was
duke@1 124 * opened for writing and does not support reading
duke@1 125 * @throws UnsupportedOperationException if this kind of
duke@1 126 * file object does not support character access
duke@1 127 * @throws IOException if an I/O error occurred
duke@1 128 */
duke@1 129 CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;
duke@1 130
duke@1 131 /**
duke@1 132 * Gets a Writer for this file object.
duke@1 133 *
duke@1 134 * @return a Writer
duke@1 135 * @throws IllegalStateException if this file object was
duke@1 136 * opened for reading and does not support writing
duke@1 137 * @throws UnsupportedOperationException if this kind of
duke@1 138 * file object does not support character access
duke@1 139 * @throws IOException if an I/O error occurred
duke@1 140 */
duke@1 141 Writer openWriter() throws IOException;
duke@1 142
duke@1 143 /**
duke@1 144 * Gets the time this file object was last modified. The time is
duke@1 145 * measured in milliseconds since the epoch (00:00:00 GMT, January
duke@1 146 * 1, 1970).
duke@1 147 *
duke@1 148 * @return the time this file object was last modified; or 0 if
duke@1 149 * the file object does not exist, if an I/O error occurred, or if
duke@1 150 * the operation is not supported
duke@1 151 */
duke@1 152 long getLastModified();
duke@1 153
duke@1 154 /**
duke@1 155 * Deletes this file object. In case of errors, returns false.
duke@1 156 * @return true if and only if this file object is successfully
duke@1 157 * deleted; false otherwise
duke@1 158 */
duke@1 159 boolean delete();
duke@1 160
duke@1 161 }

mercurial