- java.lang.Object
-
- 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
JavaFileObject.Kind
-
-
Field Summary
Fields Modifier and Type Field and 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 and Description protected
SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.
-
Method Summary
Methods Modifier and Type Method and Description boolean
delete()
This implementation does nothing.Modifier
getAccessLevel()
This implementation returnsnull
.CharSequence
getCharContent(boolean ignoreEncodingErrors)
This implementation always throws UnsupportedOperationException.JavaFileObject.Kind
getKind()
Gets the kind of this file object.long
getLastModified()
This implementation returns0L
.String
getName()
Gets a user-friendly name for this file object.NestingKind
getNestingKind()
This implementation returnsnull
.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.
-
-
-
Field Detail
-
uri
protected final URI uri
A URI for this file object.
-
kind
protected final JavaFileObject.Kind kind
The kind of this file object.
-
-
Constructor Detail
-
SimpleJavaFileObject
protected SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.- Parameters:
uri
- the URI for this file objectkind
- the kind of this file object
-
-
Method Detail
-
toUri
public URI toUri()
Description copied from interface:FileObject
Returns a URI identifying this file object.- Specified by:
toUri
in interfaceFileObject
- Returns:
- a URI
-
getName
public String getName()
Description copied from interface:FileObject
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 method might returnfile:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
.- Specified by:
getName
in interfaceFileObject
- Returns:
- a user-friendly name
-
openInputStream
public InputStream openInputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObject
is obeyed.- Specified by:
openInputStream
in interfaceFileObject
- Returns:
- an InputStream
- Throws:
IOException
- if an I/O error occurred
-
openOutputStream
public OutputStream openOutputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObject
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
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
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
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObject
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
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract ofFileObject
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()
This implementation returns0L
. Subclasses can change this behavior as long as the contract ofFileObject
is obeyed.- Specified by:
getLastModified
in interfaceFileObject
- Returns:
0L
-
delete
public boolean delete()
This implementation does nothing. Subclasses can change this behavior as long as the contract ofFileObject
is obeyed.- Specified by:
delete
in interfaceFileObject
- Returns:
false
-
getKind
public JavaFileObject.Kind getKind()
Description copied from interface:JavaFileObject
Gets the kind of this file object.- Specified by:
getKind
in interfaceJavaFileObject
- Returns:
this.kind
-
isNameCompatible
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind 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 tosimpleName + kind.extension
or if it ends with"/" + simpleName + kind.extension
.This method calls
getKind()
andtoUri()
and does not access the fieldsuri
andkind
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()
This implementation returnsnull
. Subclasses can change this behavior as long as the contract ofJavaFileObject
is obeyed.- Specified by:
getNestingKind
in interfaceJavaFileObject
- Returns:
- the nesting kind, or
null
if the nesting kind is not known
-
getAccessLevel
public Modifier getAccessLevel()
This implementation returnsnull
. Subclasses can change this behavior as long as the contract ofJavaFileObject
is obeyed.- Specified by:
getAccessLevel
in interfaceJavaFileObject
- Returns:
- the access level
-
toString
public String toString()
Description copied from class:Object
Returns a string representation of the object. In general, thetoString
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 classObject
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())
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/tools/SimpleJavaFileObject.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.