SimpleJavaFileObject (Java Platform SE 8 ) (original) (raw)
- javax.tools.SimpleJavaFileObject
All Implemented Interfaces:
FileObject, JavaFileObject
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.
Since:
1.6
Nested Class Summary
* ### Nested classes/interfaces inherited from interface javax.tools.[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools") `[JavaFileObject.Kind](../../javax/tools/JavaFileObject.Kind.html "enum in javax.tools")`
Field Summary
Fields
Modifier and Type Field Description protected JavaFileObject.Kind kind The kind of this file object. protected URI uri A URI for this file object. Constructor Summary
Constructors
Modifier Constructor Description protected SimpleJavaFileObject(URI uri,JavaFileObject.Kind kind) Construct a SimpleJavaFileObject of the given kind and with the given URI. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description boolean delete() This implementation does nothing. Modifier getAccessLevel() This implementation returns null. CharSequence getCharContent(boolean ignoreEncodingErrors) This implementation always throws UnsupportedOperationException. JavaFileObject.Kind getKind() Gets the kind of this file object. long getLastModified() This implementation returns 0L. String getName() Gets a user-friendly name for this file object. NestingKind getNestingKind() This implementation returns null. boolean isNameCompatible(String simpleName,JavaFileObject.Kind kind) 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(boolean ignoreEncodingErrors) Wraps the result of getCharContent(boolean) in a Reader. Writer openWriter() Wraps the result of openOutputStream in a Writer. String toString() Returns a string representation of the object. URI toUri() Returns a URI identifying this file object. * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone--), [equals](../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [hashCode](../../java/lang/Object.html#hashCode--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### uri protected final [URI](../../java/net/URI.html "class in java.net") uri A URI for this file object. * #### kind protected final [JavaFileObject.Kind](../../javax/tools/JavaFileObject.Kind.html "enum in javax.tools") kind The kind of this file object.
Constructor Detail
* #### SimpleJavaFileObject protected SimpleJavaFileObject([URI](../../java/net/URI.html "class in java.net") uri, [JavaFileObject.Kind](../../javax/tools/JavaFileObject.Kind.html "enum in javax.tools") kind) 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 object
Method Detail
* #### toUri public [URI](../../java/net/URI.html "class in java.net") toUri() Description copied from interface: `[FileObject](../../javax/tools/FileObject.html#toUri--)` Returns a URI identifying this file object. Specified by: `[toUri](../../javax/tools/FileObject.html#toUri--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: a URI * #### getName public [String](../../java/lang/String.html "class in java.lang") getName() Description copied from interface: `[FileObject](../../javax/tools/FileObject.html#getName--)` 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](../../javax/tools/FileObject.html#toUri--) method might return `file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java`. Specified by: `[getName](../../javax/tools/FileObject.html#getName--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: a user-friendly name * #### openInputStream public [InputStream](../../java/io/InputStream.html "class in java.io") openInputStream() throws [IOException](../../java/io/IOException.html "class in java.io") Specified by: `[openInputStream](../../javax/tools/FileObject.html#openInputStream--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: an InputStream Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if an I/O error occurred * #### openOutputStream public [OutputStream](../../java/io/OutputStream.html "class in java.io") openOutputStream() throws [IOException](../../java/io/IOException.html "class in java.io") Specified by: `[openOutputStream](../../javax/tools/FileObject.html#openOutputStream--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: an OutputStream Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if an I/O error occurred * #### openReader public [Reader](../../java/io/Reader.html "class in java.io") openReader(boolean ignoreEncodingErrors) throws [IOException](../../java/io/IOException.html "class in java.io") Wraps the result of [getCharContent(boolean)](../../javax/tools/SimpleJavaFileObject.html#getCharContent-boolean-) in a Reader. Subclasses can change this behavior as long as the contract of[FileObject](../../javax/tools/FileObject.html "interface in javax.tools") is obeyed. Specified by: `[openReader](../../javax/tools/FileObject.html#openReader-boolean-)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Parameters: `ignoreEncodingErrors` \- ignore encoding errors if true Returns: a Reader wrapping the result of getCharContent Throws: `[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this file object was opened for writing and does not support reading `[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang")` \- if this kind of file object does not support character access `[IOException](../../java/io/IOException.html "class in java.io")` \- if an I/O error occurred * #### getCharContent public [CharSequence](../../java/lang/CharSequence.html "interface in java.lang") getCharContent(boolean ignoreEncodingErrors) throws [IOException](../../java/io/IOException.html "class in java.io") Specified by: `[getCharContent](../../javax/tools/FileObject.html#getCharContent-boolean-)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Parameters: `ignoreEncodingErrors` \- ignore encoding errors if true Returns: a CharSequence if available; `null` otherwise Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if an I/O error occurred * #### openWriter public [Writer](../../java/io/Writer.html "class in java.io") openWriter() throws [IOException](../../java/io/IOException.html "class in java.io") Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of [FileObject](../../javax/tools/FileObject.html "interface in javax.tools") is obeyed. Specified by: `[openWriter](../../javax/tools/FileObject.html#openWriter--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: a Writer wrapping the result of openOutputStream Throws: `[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this file object was opened for reading and does not support writing `[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang")` \- if this kind of file object does not support character access `[IOException](../../java/io/IOException.html "class in java.io")` \- if an I/O error occurred * #### getLastModified public long getLastModified() This implementation returns `0L`. Subclasses can change this behavior as long as the contract of [FileObject](../../javax/tools/FileObject.html "interface in javax.tools") is obeyed. Specified by: `[getLastModified](../../javax/tools/FileObject.html#getLastModified--)` in interface `[FileObject](../../javax/tools/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](../../javax/tools/FileObject.html "interface in javax.tools") is obeyed. Specified by: `[delete](../../javax/tools/FileObject.html#delete--)` in interface `[FileObject](../../javax/tools/FileObject.html "interface in javax.tools")` Returns: `false` * #### getKind public [JavaFileObject.Kind](../../javax/tools/JavaFileObject.Kind.html "enum in javax.tools") getKind() Gets the kind of this file object. Specified by: `[getKind](../../javax/tools/JavaFileObject.html#getKind--)` in interface `[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools")` Returns: `this.kind` * #### isNameCompatible public boolean isNameCompatible([String](../../java/lang/String.html "class in java.lang") simpleName, [JavaFileObject.Kind](../../javax/tools/JavaFileObject.Kind.html "enum in javax.tools") 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()](../../javax/tools/SimpleJavaFileObject.html#getKind--) and [toUri()](../../javax/tools/SimpleJavaFileObject.html#toUri--) and does not access the fields [uri](../../javax/tools/SimpleJavaFileObject.html#uri) and [kind](../../javax/tools/SimpleJavaFileObject.html#kind) directly. Subclasses can change this behavior as long as the contract of [JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools") is obeyed. Specified by: `[isNameCompatible](../../javax/tools/JavaFileObject.html#isNameCompatible-java.lang.String-javax.tools.JavaFileObject.Kind-)` in interface `[JavaFileObject](../../javax/tools/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 otherwise * #### getNestingKind public [NestingKind](../../javax/lang/model/element/NestingKind.html "enum in javax.lang.model.element") getNestingKind() This implementation returns `null`. Subclasses can change this behavior as long as the contract of[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools") is obeyed. Specified by: `[getNestingKind](../../javax/tools/JavaFileObject.html#getNestingKind--)` in interface `[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools")` Returns: the nesting kind, or `null` if the nesting kind is not known * #### getAccessLevel public [Modifier](../../javax/lang/model/element/Modifier.html "enum in javax.lang.model.element") getAccessLevel() This implementation returns `null`. Subclasses can change this behavior as long as the contract of[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools") is obeyed. Specified by: `[getAccessLevel](../../javax/tools/JavaFileObject.html#getAccessLevel--)` in interface `[JavaFileObject](../../javax/tools/JavaFileObject.html "interface in javax.tools")` Returns: the access level * #### toString public [String](../../java/lang/String.html "class in java.lang") toString() Description copied from class: `[Object](../../java/lang/Object.html#toString--)` 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()) > Overrides: `[toString](../../java/lang/Object.html#toString--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: a string representation of the object.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.