@NonNull LanguageVersion getLanguageVersion()
Returns the language version which should be used to process this file. This is a property of the file, which allows sources for different language versions to be processed in the same PMD run. It also makes it so, that the file extension is not interpreted to find out the language version after the initial file collection phase.
FileId getFileId()
Returns an identifier for this file. This should not be interpreted as a
File
, it may not be a file on this filesystem. Two distinct text files should have distinct path IDs, and from one analysis to the next, the path ID of logically identical files should be the same.
default boolean isReadOnly()
Returns true if this file cannot be written to. In that case,
writeContents(TextFileContent)
will throw an exception. In the general case, nothing prevents this method's result from changing from one invocation to another.
default void writeContents(TextFileContent content) throws IOException
Writes the given content to the underlying character store.
content
- Content to write, with lines separated by the given line separator
IOException
- If this instance is closed
IOException
- If an error occurs
ReadOnlyFileException
- If this text source is read-only
TextFileContent readContents() throws IOException
Reads the contents of the underlying character source.
IOException
- If this instance is closed
IOException
- If reading causes an IOException
void close() throws IOException
Release resources associated with this text file. Is a noop if it is called several times.
close
in interface AutoCloseable
close
in interface Closeable
IOException
- If an IO exception occurs
boolean equals(Object o)
Text file equality is implementation-defined. The only constraint is that equal text files should have equal path IDs (and the usual properties mandated by
Object.equals(Object)
).
static TextFile forPath(Path path, Charset charset, LanguageVersion languageVersion)
Returns an instance of this interface reading and writing to a file. See
builderForPath
for more info.
path
- Path to the file
charset
- Encoding to use
languageVersion
- Language version to use
NullPointerException
- If any parameter is null
static TextFileBuilder builderForPath(Path path, Charset charset, LanguageVersion languageVersion)
Returns a builder for a textfile that reads and write to the file. The returned instance may be read-only. If the file is not a regular file (eg, a directory), or does not exist, then
readContents()
will throw.
The display name is by default the given path (without normalization), while the path id is the absolute path.
path
- Path to the file
charset
- Encoding to use
languageVersion
- Language version to use
NullPointerException
- If any parameter is null
static TextFile forCharSeq(CharSequence charseq, FileId fileId, LanguageVersion languageVersion)
Returns a read-only TextFile reading from a string. Note that this will normalize the text, in such a way that
readContents()
may not produce exactly the same char sequence.
charseq
- Text of the file
fileId
- File name to use as path id
languageVersion
- Language version
NullPointerException
- If any parameter is null
static TextFileBuilder builderForCharSeq(CharSequence charseq, FileId fileId, LanguageVersion languageVersion)
Returns a read-only TextFile reading from a string. Note that this will normalize the text, in such a way that
readContents()
may not produce exactly the same char sequence.
charseq
- Text of the file
fileId
- File name to use as path id
languageVersion
- Language version
NullPointerException
- If any parameter is null
static TextFile forReader(Reader reader, FileId fileId, LanguageVersion languageVersion)
Returns a read-only instance of this interface reading from a reader. The reader is first read when
readContents()
is first called, and is closed when that method exits. Note that this may only be called once, afterwards,
readContents()
will throw an
IOException
.
reader
- Text of the file
fileId
- File name to use as path id
languageVersion
- Language version
NullPointerException
- If any parameter is null
static TextFileBuilder builderForReader(Reader reader, FileId fileId, LanguageVersion languageVersion)
Returns a read-only builder reading from a reader. The reader is first read when
readContents()
is first called, and is closed when that method exits. Note that this may only be called once, afterwards,
readContents()
will throw an
IOException
.
reader
- Text of the file
fileId
- File name to use as path id
languageVersion
- Language version
NullPointerException
- If any parameter is null
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4