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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial