| Modifier and Type | Field and Description |
|---|---|
| protected final JavaFileObject. | kind
The kind of this file object. |
| protected final URI | uri
A URI for this file object. |
| Access | Constructor and Description |
|---|---|
| protected | SimpleJavaFileObject(URI
the URI for this file object uri, JavaFileObject.the kind of this file object kindConstruct a SimpleJavaFileObject of the given kind and with the given URI. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public static JavaFileObject | Returns: aJavaFileObject representing the given source content.that should be used for the resulting uri, String JavaFileObjectthe content of the content)JavaFileObjectCreates a |
| public Modifier | getAccessLevel()
Implements javax. Provides a hint about the access level of the class represented by this file object. |
| public CharSequence | getCharContent(boolean ignoreEncodingErrors)
Implements javax. Returns the character content of this file object, if available. |
| public JavaFileObject. | Returns: this.kindImplements javax. Returns the kind of this file object. |
| public long | Returns: 0LImplements javax. Returns the time this file object was last modified. |
| public String | getName()
Implements javax. Returns a user-friendly name for this file object. |
| public NestingKind | getNestingKind()
Implements javax. Provides a hint about the nesting level of the class represented by this file object. |
| public boolean | isNameCompatible(String simpleName, JavaFileObject.
Implements javax. Checks if this file object is compatible with the specified simple name and kind. |
| public InputStream | openInputStream()
Implements javax. Returns an InputStream for this file object. |
| public OutputStream | openOutputStream()
Implements javax. Returns an OutputStream for this file object. |
| public Reader | Returns: a Reader wrapping the result of getCharContentImplements javax. Returns a reader for this object. |
| public Writer | Returns: a Writer wrapping the result of openOutputStreamImplements javax. Returns a Writer for this file object. |
| public String | |
| public URI |
| kind | back to summary |
|---|---|
| protected final JavaFileObject. The kind of this file object. | |
| uri | back to summary |
|---|---|
| protected final URI uri A URI for this file object. | |
| SimpleJavaFileObject | back to summary |
|---|---|
| protected SimpleJavaFileObject(URI uri, JavaFileObject. Construct a SimpleJavaFileObject of the given kind and with the given URI.
| |
| delete | back to summary |
|---|---|
| public boolean delete() Implements javax. Doc from javax. Deletes this file object. In case of errors, returns false. Implementation Specification This implementation does nothing.
| |
| forSource | back to summary |
|---|---|
| public static JavaFileObject forSource(URI uri, String content) Creates a The provided All other methods will behave as described in the documentation in this class,
as if the constructor is called with This method can be, for example, used to compile an in-memory String to a set of classfile in a target directory: var code = """ public class CompiledCode {} """; var compiler = ToolProvider.getSystemJavaCompiler(); var targetDirectory = "..."; var task = compiler.getTask(null, null, null, List.of("-d", targetDirectory), null, List.of(SimpleJavaFileObject.forSource(URI.create("CompiledCode.java"), code))); if (!task.call()) { throw new IllegalStateException("Compilation failed!"); }
| |
| getAccessLevel | back to summary |
|---|---|
| public Modifier getAccessLevel() Implements javax. Doc from javax. Provides a hint about the access level of the class represented
by this file object. If the access level is not known or
this file object does not represent a class file this method
returns Implementation Specification This implementation returns
| |
| getCharContent | back to summary |
|---|---|
| public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException Implements javax. Doc from javax. Returns the character content of this file object, if available.
Any byte that cannot be decoded will be replaced by the default
translation character. In addition, a diagnostic may be
reported unless Implementation Specification This implementation always throws UnsupportedOperationException.
| |
| getKind | back to summary |
|---|---|
| public JavaFileObject. Implements javax. Doc from javax. Returns the kind of this file object.
| |
| getLastModified | back to summary |
|---|---|
| public long getLastModified() Implements javax. Doc from javax. Returns the time this file object was last modified. The time is measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970). Implementation Specification This implementation returns
| |
| getName | back to summary |
|---|---|
| public String getName() Implements javax. Doc from javax. 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
| |
| getNestingKind | back to summary |
|---|---|
| public NestingKind getNestingKind() Implements javax. Doc from javax. Provides a hint about the nesting level of the class
represented by this file object. This method may return
Implementation Specification This implementation returns
| |
| isNameCompatible | back to summary |
|---|---|
| public boolean isNameCompatible(String simpleName, JavaFileObject. Implements javax. Doc from javax. Checks if this file object is compatible with the specified simple name and kind. A simple name is a single identifier (not qualified) as defined in The Java Language Specification, section 6.2. Implementation Specification 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
This method calls
| |
| openInputStream | back to summary |
|---|---|
| public InputStream openInputStream() throws IOException Implements javax. Doc from javax. Returns an InputStream for this file object. Implementation Specification This implementation always throws UnsupportedOperationException.
| |
| openOutputStream | back to summary |
|---|---|
| public OutputStream openOutputStream() throws IOException Implements javax. Doc from javax. Returns an OutputStream for this file object. Implementation Specification This implementation always throws UnsupportedOperationException.
| |
| openReader | back to summary |
|---|---|
| public Reader openReader(boolean ignoreEncodingErrors) throws IOException Implements javax. Doc from javax. Returns a reader for this object. The returned reader will
replace bytes that cannot be decoded with the default
translation character. In addition, the reader may report a
diagnostic unless Implementation Specification This implementation wraps the result of
| |
| openWriter | back to summary |
|---|---|
| public Writer openWriter() throws IOException Implements javax. Doc from javax. Returns a Writer for this file object. Implementation Specification This implementation wraps the result of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| toUri | back to summary |
|---|---|
| public URI toUri() Implements javax. Doc from javax. Returns a URI identifying this file object.
| |