001    /* FileObject.java --
002       Copyright (C) 2008  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    package javax.tools;
039    
040    import java.io.IOException;
041    import java.io.InputStream;
042    import java.io.OutputStream;
043    import java.io.Reader;
044    import java.io.Writer;
045    import java.net.URI;
046    
047    /**
048     * Abstraction for all kinds of file objects used by tools, e.g. regular files,
049     * memory cache, or database data.
050     *
051     * @author Roman Kennke (roman@kennke.org)
052     *
053     * @since 1.6
054     */
055    public interface FileObject
056    {
057    
058      /**
059       * Returns a URI that represents this file object.
060       *
061       * @return a URI that represents this file object
062       */
063      URI toUri();
064    
065      /**
066       * Returns a name for this file object. The exact name is implementation
067       * dependent.
068       *
069       * @return a name for this file object
070       */
071      String getName();
072    
073      /**
074       * Opens this file for reading and returns an input stream.
075       *
076       * @return an input stream to read this file object
077       *
078       * @throws IOException if an I/O error occured
079       * @throws IllegalStateException if this file was opened for writing and
080       *         does not support reading
081       * @throws UnsupportedOperationException if this kind of file does not allow
082       *         byte reading
083       */
084      InputStream openInputStream() throws IOException;
085    
086      /**
087       * Opens this file for writing and returns an output stream.
088       *
089       * @return an output stream for writing this file object
090       *
091       * @throws IOException if an I/O error occurs
092       * @throws IllegalStateException if this file was opened for reading and
093       *         does not support writing
094       * @throws UnsupportedOperationException if this kind of file does not allow
095       *         byte writing
096       */
097      OutputStream openOutputStream() throws IOException;
098    
099      /**
100       * Opens this file for reading and returns a reader.
101       *
102       * @param ignoreEncodingErrors <code>true</code> when encoding errors should be ignored
103       *                             <code>false</code> otherwise
104       * @return a reader for reading this file object
105       *
106       * @throws IOException if an I/O error occurs
107       * @throws IllegalStateException if this file was opened for writing and
108       *         does not support reading
109       * @throws UnsupportedOperationException if this kind of file does not allow
110       *         character reading
111       */
112      Reader openReader(boolean ignoreEncodingErrors) throws IOException;
113    
114      /**
115       * Returns the character content of the file, if available. Any byte
116       * that cannot be decoded will be replaced by the default replacement
117       * character. A diagnostic may be reported, unless
118       * <code>ignoreEncodingErrors</code> is <code>true</code>.
119       *
120       * @param ignoreEncodingErrors <code>true</code> when encoding errors should be ignored
121       *                             <code>false</code> otherwise
122       * @return the character content, or <code>null</code> if not available
123       *
124       * @throws IOException if an I/O error occurs
125       */
126      CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException;
127    
128      /**
129       * Opens this file for writer and returns a writer.
130       *
131       * @return a writer for writing this file object
132       *
133       * @throws IOException if an I/O error occurs
134       * @throws IllegalStateException if this file was opened for reading and
135       *         does not support writing
136       * @throws UnsupportedOperationException if this kind of file does not allow
137       *         character writing
138       */
139      Writer openWriter() throws IOException;
140    
141      /**
142       * Returns the time when the file was last modified. The time is measured
143       * like in <code>System.currentTimeMillis()</code>.
144       *
145       * @return the time when the file was last modified
146       */
147      long getLastModified();
148    
149      /**
150       * Deletes this file object. In case of errors this returns
151       * <code>false</code>.
152       *
153       * @return <code>true</code> when the file deletion was successful,
154       *         <code>false</code> otherwise
155       */
156      boolean delete();
157    }