Path: blob/master/src/java.compiler/share/classes/javax/tools/FileObject.java
41152 views
/*1* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import java.io.IOException;28import java.io.InputStream;29import java.io.OutputStream;30import java.io.Reader;31import java.io.Writer;32import java.net.URI;3334/**35* File abstraction for tools. In this context, <em>file</em> means36* an abstraction of regular files and other sources of data. For37* example, a file object can be used to represent regular files,38* memory cache, or data in databases.39*40* <p>All methods in this interface might throw a SecurityException if41* a security exception occurs.42*43* <p>Unless explicitly allowed, all methods in this interface might44* throw a NullPointerException if given a {@code null} argument.45*46* @author Peter von der Ahé47* @author Jonathan Gibbons48* @since 1.649*/50public interface FileObject {5152/**53* Returns a URI identifying this file object.54* @return a URI55*/56URI toUri();5758/**59* Returns a user-friendly name for this file object. The exact60* value returned is not specified but implementations should take61* care to preserve names as given by the user. For example, if62* the user writes the filename {@code "BobsApp\Test.java"} on63* the command line, this method should return {@code64* "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri}65* method might return {@code66* file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}.67*68* @return a user-friendly name69*/70String getName();7172/**73* Returns an InputStream for this file object.74*75* @return an InputStream76* @throws IllegalStateException if this file object was77* opened for writing and does not support reading78* @throws UnsupportedOperationException if this kind of file79* object does not support byte access80* @throws IOException if an I/O error occurred81*/82InputStream openInputStream() throws IOException;8384/**85* Returns an OutputStream for this file object.86*87* @return an OutputStream88* @throws IllegalStateException if this file object was89* opened for reading and does not support writing90* @throws UnsupportedOperationException if this kind of91* file object does not support byte access92* @throws IOException if an I/O error occurred93*/94OutputStream openOutputStream() throws IOException;9596/**97* Returns a reader for this object. The returned reader will98* replace bytes that cannot be decoded with the default99* translation character. In addition, the reader may report a100* diagnostic unless {@code ignoreEncodingErrors} is true.101*102* @param ignoreEncodingErrors ignore encoding errors if true103* @return a Reader104* @throws IllegalStateException if this file object was105* opened for writing and does not support reading106* @throws UnsupportedOperationException if this kind of107* file object does not support character access108* @throws IOException if an I/O error occurred109*/110Reader openReader(boolean ignoreEncodingErrors) throws IOException;111112/**113* Returns the character content of this file object, if available.114* Any byte that cannot be decoded will be replaced by the default115* translation character. In addition, a diagnostic may be116* reported unless {@code ignoreEncodingErrors} is true.117*118* @param ignoreEncodingErrors ignore encoding errors if true119* @return a CharSequence if available; {@code null} otherwise120* @throws IllegalStateException if this file object was121* opened for writing and does not support reading122* @throws UnsupportedOperationException if this kind of123* file object does not support character access124* @throws IOException if an I/O error occurred125*/126CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;127128/**129* Returns a Writer for this file object.130*131* @return a Writer132* @throws IllegalStateException if this file object was133* opened for reading and does not support writing134* @throws UnsupportedOperationException if this kind of135* file object does not support character access136* @throws IOException if an I/O error occurred137*/138Writer openWriter() throws IOException;139140/**141* Returns the time this file object was last modified. The time is142* measured in milliseconds since the epoch (00:00:00 GMT, January143* 1, 1970).144*145* @return the time this file object was last modified; or 0 if146* the file object does not exist, if an I/O error occurred, or if147* the operation is not supported148*/149long getLastModified();150151/**152* Deletes this file object. In case of errors, returns false.153* @return true if and only if this file object is successfully154* deleted; false otherwise155*/156boolean delete();157158}159160161