FileObject
, JavaFileObject
public class SimpleJavaFileObject extends Object implements JavaFileObject
JavaFileObject.Kind
Modifier and Type | Field | Description |
---|---|---|
protected final JavaFileObject.Kind |
kind |
The kind of this file object. |
protected final URI |
uri |
A URI for this file object. |
Modifier | Constructor | Description |
---|---|---|
protected |
Construct a SimpleJavaFileObject of the given kind and with the given URI. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
delete() |
This implementation does nothing. |
Modifier |
getAccessLevel() |
This implementation returns null . |
CharSequence |
getCharContent |
This implementation always throws UnsupportedOperationException. |
JavaFileObject.Kind |
getKind() |
Returns the kind of this file object. |
long |
getLastModified() |
This implementation returns 0L . |
String |
getName() |
Returns a user-friendly name for this file object. |
NestingKind |
getNestingKind() |
This implementation returns null . |
boolean |
isNameCompatible |
This implementation compares the path of its URI to the given simple name. |
InputStream |
openInputStream() |
This implementation always throws UnsupportedOperationException. |
OutputStream |
openOutputStream() |
This implementation always throws UnsupportedOperationException. |
Reader |
openReader |
Wraps the result of getCharContent(boolean) in a Reader. |
Writer |
openWriter() |
Wraps the result of openOutputStream in a Writer. |
URI |
toUri() |
Returns a URI identifying this file object. |
protected final URI uri
protected final JavaFileObject.Kind kind
protected SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
uri
- the URI for this file objectkind
- the kind of this file objectpublic URI toUri()
FileObject
toUri
in interface FileObject
public String getName()
FileObject
"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
FileObject
is obeyed.openInputStream
in interface FileObject
IOException
- if an I/O error occurredpublic OutputStream openOutputStream() throws IOException
FileObject
is obeyed.openOutputStream
in interface FileObject
IOException
- if an I/O error occurredpublic Reader openReader(boolean ignoreEncodingErrors) throws IOException
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
FileObject
is obeyed.getCharContent
in interface FileObject
ignoreEncodingErrors
- ignore encoding errors if truenull
otherwiseIOException
- if an I/O error occurredpublic Writer openWriter() throws IOException
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()
0L
. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.getLastModified
in interface FileObject
0L
public boolean delete()
FileObject
is obeyed.delete
in interface FileObject
false
public JavaFileObject.Kind getKind()
JavaFileObject
getKind
in interface JavaFileObject
this.kind
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind)
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()
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()
null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.getAccessLevel
in interface JavaFileObject
© 1993, 2023, 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.
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/tools/SimpleJavaFileObject.html