Wed, 08 Oct 2014 14:16:40 -0700
Merge
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2006, 2008, Oracle and/or its affiliates. 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 |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle 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 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * 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.InputStream; |
duke@1 | 30 | import java.io.OutputStream; |
duke@1 | 31 | import java.io.Reader; |
duke@1 | 32 | import java.io.Writer; |
duke@1 | 33 | import java.net.URI; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * File abstraction for tools. In this context, <em>file</em> means |
duke@1 | 37 | * an abstraction of regular files and other sources of data. For |
duke@1 | 38 | * example, a file object can be used to represent regular files, |
duke@1 | 39 | * memory cache, or data in databases. |
duke@1 | 40 | * |
duke@1 | 41 | * <p>All methods in this interface might throw a SecurityException if |
duke@1 | 42 | * a security exception occurs. |
duke@1 | 43 | * |
duke@1 | 44 | * <p>Unless explicitly allowed, all methods in this interface might |
duke@1 | 45 | * throw a NullPointerException if given a {@code null} argument. |
duke@1 | 46 | * |
duke@1 | 47 | * @author Peter von der Ahé |
duke@1 | 48 | * @author Jonathan Gibbons |
duke@1 | 49 | * @since 1.6 |
duke@1 | 50 | */ |
duke@1 | 51 | public interface FileObject { |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * Returns a URI identifying this file object. |
duke@1 | 55 | * @return a URI |
duke@1 | 56 | */ |
duke@1 | 57 | URI toUri(); |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Gets a user-friendly name for this file object. The exact |
duke@1 | 61 | * value returned is not specified but implementations should take |
duke@1 | 62 | * care to preserve names as given by the user. For example, if |
duke@1 | 63 | * the user writes the filename {@code "BobsApp\Test.java"} on |
duke@1 | 64 | * the command line, this method should return {@code |
duke@1 | 65 | * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri} |
duke@1 | 66 | * method might return {@code |
duke@1 | 67 | * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}. |
duke@1 | 68 | * |
duke@1 | 69 | * @return a user-friendly name |
duke@1 | 70 | */ |
duke@1 | 71 | String getName(); |
duke@1 | 72 | |
duke@1 | 73 | /** |
duke@1 | 74 | * Gets an InputStream for this file object. |
duke@1 | 75 | * |
duke@1 | 76 | * @return an InputStream |
duke@1 | 77 | * @throws IllegalStateException if this file object was |
duke@1 | 78 | * opened for writing and does not support reading |
duke@1 | 79 | * @throws UnsupportedOperationException if this kind of file |
duke@1 | 80 | * object does not support byte access |
duke@1 | 81 | * @throws IOException if an I/O error occurred |
duke@1 | 82 | */ |
duke@1 | 83 | InputStream openInputStream() throws IOException; |
duke@1 | 84 | |
duke@1 | 85 | /** |
duke@1 | 86 | * Gets an OutputStream for this file object. |
duke@1 | 87 | * |
duke@1 | 88 | * @return an OutputStream |
duke@1 | 89 | * @throws IllegalStateException if this file object was |
duke@1 | 90 | * opened for reading and does not support writing |
duke@1 | 91 | * @throws UnsupportedOperationException if this kind of |
duke@1 | 92 | * file object does not support byte access |
duke@1 | 93 | * @throws IOException if an I/O error occurred |
duke@1 | 94 | */ |
duke@1 | 95 | OutputStream openOutputStream() throws IOException; |
duke@1 | 96 | |
duke@1 | 97 | /** |
duke@1 | 98 | * Gets a reader for this object. The returned reader will |
duke@1 | 99 | * replace bytes that cannot be decoded with the default |
duke@1 | 100 | * translation character. In addition, the reader may report a |
duke@1 | 101 | * diagnostic unless {@code ignoreEncodingErrors} is true. |
duke@1 | 102 | * |
duke@1 | 103 | * @param ignoreEncodingErrors ignore encoding errors if true |
duke@1 | 104 | * @return a Reader |
duke@1 | 105 | * @throws IllegalStateException if this file object was |
duke@1 | 106 | * opened for writing and does not support reading |
duke@1 | 107 | * @throws UnsupportedOperationException if this kind of |
duke@1 | 108 | * file object does not support character access |
duke@1 | 109 | * @throws IOException if an I/O error occurred |
duke@1 | 110 | */ |
duke@1 | 111 | Reader openReader(boolean ignoreEncodingErrors) throws IOException; |
duke@1 | 112 | |
duke@1 | 113 | /** |
duke@1 | 114 | * Gets the character content of this file object, if available. |
duke@1 | 115 | * Any byte that cannot be decoded will be replaced by the default |
duke@1 | 116 | * translation character. In addition, a diagnostic may be |
duke@1 | 117 | * reported unless {@code ignoreEncodingErrors} is true. |
duke@1 | 118 | * |
duke@1 | 119 | * @param ignoreEncodingErrors ignore encoding errors if true |
duke@1 | 120 | * @return a CharSequence if available; {@code null} otherwise |
duke@1 | 121 | * @throws IllegalStateException if this file object was |
duke@1 | 122 | * opened for writing and does not support reading |
duke@1 | 123 | * @throws UnsupportedOperationException if this kind of |
duke@1 | 124 | * file object does not support character access |
duke@1 | 125 | * @throws IOException if an I/O error occurred |
duke@1 | 126 | */ |
duke@1 | 127 | CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException; |
duke@1 | 128 | |
duke@1 | 129 | /** |
duke@1 | 130 | * Gets a Writer for this file object. |
duke@1 | 131 | * |
duke@1 | 132 | * @return a Writer |
duke@1 | 133 | * @throws IllegalStateException if this file object was |
duke@1 | 134 | * opened for reading and does not support writing |
duke@1 | 135 | * @throws UnsupportedOperationException if this kind of |
duke@1 | 136 | * file object does not support character access |
duke@1 | 137 | * @throws IOException if an I/O error occurred |
duke@1 | 138 | */ |
duke@1 | 139 | Writer openWriter() throws IOException; |
duke@1 | 140 | |
duke@1 | 141 | /** |
duke@1 | 142 | * Gets the time this file object was last modified. The time is |
duke@1 | 143 | * measured in milliseconds since the epoch (00:00:00 GMT, January |
duke@1 | 144 | * 1, 1970). |
duke@1 | 145 | * |
duke@1 | 146 | * @return the time this file object was last modified; or 0 if |
duke@1 | 147 | * the file object does not exist, if an I/O error occurred, or if |
duke@1 | 148 | * the operation is not supported |
duke@1 | 149 | */ |
duke@1 | 150 | long getLastModified(); |
duke@1 | 151 | |
duke@1 | 152 | /** |
duke@1 | 153 | * Deletes this file object. In case of errors, returns false. |
duke@1 | 154 | * @return true if and only if this file object is successfully |
duke@1 | 155 | * deleted; false otherwise |
duke@1 | 156 | */ |
duke@1 | 157 | boolean delete(); |
duke@1 | 158 | |
duke@1 | 159 | } |