SimpleJavaFileObject (Java SE 16 & JDK 16) (original) (raw)
All Implemented Interfaces:
[FileObject](FileObject.html "interface in javax.tools")
, [JavaFileObject](JavaFileObject.html "interface in javax.tools")
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.
Since:
1.6
Nested Class Summary
Field Summary
Fields
The kind of this file object.protected [URI](../../../java.base/java/net/URI.html "class in java.net")
A URI for this file object.
Constructor Summary
Constructorsprotected
Construct a SimpleJavaFileObject of the given kind and with the given URI.
Method Summary
boolean
[delete](#delete%28%29)()
This implementation does nothing.
This implementation returns null
.[getCharContent](#getCharContent%28boolean%29)(boolean ignoreEncodingErrors)
[getKind](#getKind%28%29)()
Returns the kind of this file object.long
This implementation returns 0L
.[getName](#getName%28%29)()
Returns a user-friendly name for this file object.
This implementation returns null
.boolean
This implementation compares the path of its URI to the given simple name.[openReader](#openReader%28boolean%29)(boolean ignoreEncodingErrors)
Wraps the result of getCharContent(boolean) in a Reader.
Wraps the result of openOutputStream in a Writer.[toUri](#toUri%28%29)()
Returns a URI identifying this file object.
Methods declared in class java.lang.Object
[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)
Field Details
uri
protected final URI uri
A URI for this file object.kind
The kind of this file object.
Constructor Details
SimpleJavaFileObject
Construct a SimpleJavaFileObject of the given kind and with the given URI.
Parameters:
uri
- the URI for this file object
kind
- the kind of this file objectMethod Details
toUri
public URI toUri()
Description copied from interface:[FileObject](FileObject.html#toUri%28%29)
Returns a URI identifying this file object.
Specified by:
[toUri](FileObject.html#toUri%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
a URIgetName
Description copied from interface:
[FileObject](FileObject.html#getName%28%29)
Returns 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 returnfile:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
.
Specified by:
[getName](FileObject.html#getName%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
a user-friendly nameopenInputStream
Specified by:
[openInputStream](FileObject.html#openInputStream%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
an InputStream
Throws:
[IOException](../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurredopenOutputStream
Specified by:
[openOutputStream](FileObject.html#openOutputStream%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
an OutputStream
Throws:
[IOException](../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurredopenReader
public 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 ofFileObject is obeyed.
Specified by:
[openReader](FileObject.html#openReader%28boolean%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Parameters:
ignoreEncodingErrors
- ignore encoding errors if true
Returns:
a Reader wrapping the result of getCharContent
Throws:
[IllegalStateException](../../../java.base/java/lang/IllegalStateException.html "class in java.lang")
- if this file object was opened for writing and does not support reading
[UnsupportedOperationException](../../../java.base/java/lang/UnsupportedOperationException.html "class in java.lang")
- if this kind of file object does not support character access
[IOException](../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurredgetCharContent
Specified by:
[getCharContent](FileObject.html#getCharContent%28boolean%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Parameters:
ignoreEncodingErrors
- ignore encoding errors if true
Returns:
a CharSequence if available;null
otherwise
Throws:
[IOException](../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurredopenWriter
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of FileObject is obeyed.
Specified by:
[openWriter](FileObject.html#openWriter%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
a Writer wrapping the result of openOutputStream
Throws:
[IllegalStateException](../../../java.base/java/lang/IllegalStateException.html "class in java.lang")
- if this file object was opened for reading and does not support writing
[UnsupportedOperationException](../../../java.base/java/lang/UnsupportedOperationException.html "class in java.lang")
- if this kind of file object does not support character access
[IOException](../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurredgetLastModified
public long getLastModified()
This implementation returns0L
. Subclasses can change this behavior as long as the contract of FileObject is obeyed.
Specified by:
[getLastModified](FileObject.html#getLastModified%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
0L
delete
public boolean delete()
This implementation does nothing. Subclasses can change this behavior as long as the contract of FileObject is obeyed.
Specified by:
[delete](FileObject.html#delete%28%29)
in interface[FileObject](FileObject.html "interface in javax.tools")
Returns:
false
getKind
Returns the kind of this file object.
Specified by:
[getKind](JavaFileObject.html#getKind%28%29)
in interface[JavaFileObject](JavaFileObject.html "interface in javax.tools")
Returns:
this.kind
isNameCompatible
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.
Specified by:
[isNameCompatible](JavaFileObject.html#isNameCompatible%28java.lang.String,javax.tools.JavaFileObject.Kind%29)
in interface[JavaFileObject](JavaFileObject.html "interface in javax.tools")
Parameters:
simpleName
- a simple name of a class
kind
- a kind
Returns:
true
if this file object is compatible;false
otherwisegetNestingKind
This implementation returns
null
. Subclasses can change this behavior as long as the contract ofJavaFileObject is obeyed.
Specified by:
[getNestingKind](JavaFileObject.html#getNestingKind%28%29)
in interface[JavaFileObject](JavaFileObject.html "interface in javax.tools")
Returns:
the nesting kind, ornull
if the nesting kind is not knowngetAccessLevel
This implementation returns
null
. Subclasses can change this behavior as long as the contract ofJavaFileObject is obeyed.
Specified by:
[getAccessLevel](JavaFileObject.html#getAccessLevel%28%29)
in interface[JavaFileObject](JavaFileObject.html "interface in javax.tools")
Returns:
the access level