public class SimpleJavaFileObject extends Object implements JavaFileObject
Provides simple implementations for most methods in JavaFileObject. This class is designed to be subclassed and used as a basis for JavaFileObject implementations. Subclasses can override the implementation and specification of any method of this class as long as the general contract of JavaFileObject is obeyed.
JavaFileObject.Kind
protected final URI uri
A URI for this file object.
protected final JavaFileObject.Kind kind
The kind of this file object.
protected SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.
uri
- the URI for this file objectkind
- the kind of this file objectpublic URI toUri()
Description copied from interface: FileObject
Returns a URI identifying this file object.
toUri
in interface FileObject
public String getName()
Description copied from interface: FileObject
Gets a user-friendly name for this file object. The exact value returned is not specified but implementations should take care to preserve names as given by the user. For example, if the user writes the filename "BobsApp\Test.java"
on the command line, this method should return "BobsApp\Test.java"
whereas the toUri method might return file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
.
getName
in interface FileObject
public InputStream openInputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
openInputStream
in interface FileObject
IOException
- if an I/O error occurredpublic OutputStream openOutputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
openOutputStream
in interface FileObject
IOException
- if an I/O error occurredpublic Reader openReader(boolean ignoreEncodingErrors) throws IOException
Wraps the result of getCharContent(boolean) in a Reader. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
openReader
in interface FileObject
ignoreEncodingErrors
- ignore encoding errors if trueIllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurredpublic CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
getCharContent
in interface FileObject
ignoreEncodingErrors
- ignore encoding errors if truenull
otherwiseIOException
- if an I/O error occurredpublic Writer openWriter() throws IOException
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
openWriter
in interface FileObject
IllegalStateException
- if this file object was opened for reading and does not support writingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurredpublic long getLastModified()
This implementation returns 0L
. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
getLastModified
in interface FileObject
0L
public boolean delete()
This implementation does nothing. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
delete
in interface FileObject
false
public JavaFileObject.Kind getKind()
Description copied from interface: JavaFileObject
Gets the kind of this file object.
getKind
in interface JavaFileObject
this.kind
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind)
This implementation compares the path of its URI to the given simple name. This method returns true if the given kind is equal to the kind of this object, and if the path is equal to simpleName + kind.extension
or if it ends with "/" + simpleName + kind.extension
.
This method calls getKind()
and toUri()
and does not access the fields uri
and kind
directly.
Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
isNameCompatible
in interface JavaFileObject
simpleName
- a simple name of a classkind
- a kindtrue
if this file object is compatible; false otherwisepublic NestingKind getNestingKind()
This implementation returns null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
getNestingKind
in interface JavaFileObject
null
if the nesting kind is not knownpublic Modifier getAccessLevel()
This implementation returns null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
getAccessLevel
in interface JavaFileObject
public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString
method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@
', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.