On this page
Class SimpleJavaFileObject
- All Implemented Interfaces:
FileObject
,JavaFileObject
public class SimpleJavaFileObject extends Object implements JavaFileObject
- Since:
- 1.6
Nested Class Summary
Nested classes/interfaces declared in interface javax.tools.JavaFileObject
JavaFileObject.Kind
Field Summary
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.
|
Constructor Summary
SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
Modifier | Constructor | Description |
---|---|---|
protected |
Construct a SimpleJavaFileObject of the given kind and with the given URI.
|
Method Summary
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.
|
Field Details
uri
protected final URI uri
kind
protected final JavaFileObject.Kind kind
Constructor Details
SimpleJavaFileObject
protected SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
- Parameters:
uri
- the URI for this file objectkind
- the kind of this file object
Method Details
toUri
public URI toUri()
FileObject
- Specified by:
toUri
in interfaceFileObject
- Returns:
- a URI
getName
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
.
- Specified by:
getName
in interfaceFileObject
- Returns:
- a user-friendly name
openInputStream
public InputStream openInputStream() throws IOException
FileObject
is obeyed.
- Specified by:
openInputStream
in interfaceFileObject
- Returns:
- an InputStream
- Throws:
IOException
- if an I/O error occurred
openOutputStream
public OutputStream openOutputStream() throws IOException
FileObject
is obeyed.
- Specified by:
openOutputStream
in interfaceFileObject
- Returns:
- an OutputStream
- Throws:
IOException
- if an I/O error occurred
openReader
public Reader openReader(boolean ignoreEncodingErrors) throws IOException
FileObject
is obeyed.
- Specified by:
openReader
in interfaceFileObject
- Parameters:
ignoreEncodingErrors
- ignore encoding errors if true- Returns:
- a Reader wrapping the result of getCharContent
- Throws:
IllegalStateException
- 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 occurred
getCharContent
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
FileObject
is obeyed.
- Specified by:
getCharContent
in interfaceFileObject
- Parameters:
ignoreEncodingErrors
- ignore encoding errors if true- Returns:
-
a CharSequence if available;
null
otherwise - Throws:
IOException
- if an I/O error occurred
openWriter
public Writer openWriter() throws IOException
FileObject
is obeyed.
- Specified by:
openWriter
in interfaceFileObject
- Returns:
- a Writer wrapping the result of openOutputStream
- Throws:
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 occurred
getLastModified
public long getLastModified()
0L
. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
getLastModified
in interfaceFileObject
- Returns:
-
0L
delete
public boolean delete()
FileObject
is obeyed.
- Specified by:
delete
in interfaceFileObject
- Returns:
-
false
getKind
public JavaFileObject.Kind getKind()
JavaFileObject
- Specified by:
getKind
in interfaceJavaFileObject
- Returns:
-
this.kind
isNameCompatible
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.
- Specified by:
isNameCompatible
in interfaceJavaFileObject
- Parameters:
simpleName
- a simple name of a classkind
- a kind- Returns:
true
if this file object is compatible;false
otherwise
getNestingKind
public NestingKind getNestingKind()
null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
- Specified by:
getNestingKind
in interfaceJavaFileObject
- Returns:
-
the nesting kind, or
null
if the nesting kind is not known
getAccessLevel
public Modifier getAccessLevel()
null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
- Specified by:
getAccessLevel
in interfaceJavaFileObject
- Returns:
- the access level
© 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