public interface VfsFile extends VfsNode
Vfs systems consist of a hierarchy of VFSDirectories, some of which may contain VFSFiles. A VfsFile is a container of byte and/or text data. You can access it using streams or via direct convenience methods.
Actual VfsFile objects are implemented by a specific VFSModule.
Many of the methods here are convenience methods that should generally simply
wrap other methods. AbstractVfsFile implements
many of these for you, so you should generally extend that class rather than
implementing this interface.
Copyright 2006 Partner Software, Inc.
| Modifier and Type | Method and Description |
|---|---|
void |
appendBytes(byte[] bytes)
Appends the given bytes to the file.
|
void |
appendText(java.lang.String text)
Appends the given text to the end of the file.
|
long |
checksum()
Generates a CRC32 checksum for the file's contents.
|
VfsFile |
copyTo(Path newPath)
Copies the file to the new path.
|
VfsFile |
copyTo(VfsFile destination)
Copies the file to the given VfsFile.
|
java.io.BufferedOutputStream |
createAppendingBufferedOutputStream()
Creates a buffered output stream to write to the file.
|
java.io.BufferedWriter |
createAppendingBufferedWriter()
Creates a buffered writer to write to the file.
|
java.io.OutputStream |
createAppendingOutputStream()
Creates an output stream to append to the file.
|
java.io.Writer |
createAppendingWriter()
Creates a writer to append text to the file.
|
java.io.BufferedInputStream |
createBufferedInputStream()
Creates a buffered input stream to read from the file.
|
java.io.BufferedOutputStream |
createBufferedOutputStream()
Creates a buffered output stream to write to the file.
|
java.io.BufferedReader |
createBufferedReader()
Creates a buffered reader to read from the file.
|
java.io.BufferedWriter |
createBufferedWriter()
Creates a buffered writer to write to the file.
|
java.io.InputStream |
createInputStream()
Creates an input stream to read from the file.
|
java.io.OutputStream |
createOutputStream()
Creates an output stream to write to the file.
|
VfsRandomAccess |
createRandomAccess()
Creates a random access handle for the file.
|
java.io.Reader |
createReader()
Creates a reader to read text from the file.
|
java.io.Writer |
createWriter()
Creates a writer to write to the file.
|
DateAndTime |
getLastModified()
Returns the date and time the file was last modified.
|
long |
getLastModifiedMillis()
Returns the timestamp in milliseconds that the file was last modified.
|
VfsFile |
moveTo(Path newPath)
Moves the file to the new path.
|
VfsFile |
moveTo(VfsFile destination)
Moves the file to the given VfsFile.
|
byte[] |
readBytes()
Reads the entire file in as a byte array.
|
java.lang.String |
readText()
Read the contents of the file as text into a String.
|
java.util.List<java.lang.String> |
readTextAsLines()
Read the contents of the file as text into a list of Strings, separated by line.
|
java.util.List<java.lang.String> |
readTextAsLines(boolean trimLines)
Read the contents of the file as text, separated by line, with the option of trimming lines.
|
java.util.List<java.lang.String> |
readTextAsLines(boolean trimLines,
boolean dropEmptyLines)
Read the contents of the file as text, separated by line, with the option of trimming lines
and the option of dropping empty lines.
|
java.lang.String |
readTextRange(long start,
long end)
Returns the text from the given start (inclusive) to the given end (exclusive), in characters.
|
void |
regexReplace(java.util.List<java.lang.String> replacements)
Does a regular-expression-based text replacement on the entire file.
|
void |
regexReplace(java.lang.String... replacements)
Does a regular-expression-based text replacement on the entire file.
|
void |
remove()
Removes the file.
|
VfsFile |
renameTo(java.lang.String name)
Renames the file.
|
void |
setLastModified(DateAndTime newLast)
If possible, sets the date and time the file was last modified.
|
void |
setLastModifiedMillis(long millis)
If possible, sets the date and time the file was last modified in
milliseconds.
|
long |
size() |
void |
textReplace(java.util.List<java.lang.String> replacements)
Does a simple text replacement on the entire file.
|
void |
textReplace(java.lang.String... replacements)
Does a simple text replacement on the entire file.
|
VfsFile |
withExtension(java.lang.String extension) |
void |
writeBytes(byte[] bytes)
Writes the given bytes to the file.
|
void |
writeText(java.lang.String text)
Write the given String text to the file.
|
exists, getAbsolutePath, getBaseName, getDirectory, getExtension, getName, getPath, getUri, getUrl, getVfs, isBackup, isHidden, make, toFilelong size()
throws java.io.IOException
java.io.IOExceptionVfsFile withExtension(java.lang.String extension)
void remove()
throws java.io.IOException
java.io.IOExceptionVfsFile renameTo(java.lang.String name) throws java.io.IOException
java.io.IOExceptionVfsFile moveTo(Path newPath) throws java.io.IOException
java.io.IOExceptionVfsFile copyTo(Path newPath) throws java.io.IOException
java.io.IOExceptionVfsFile copyTo(VfsFile destination) throws java.io.IOException
java.io.IOExceptionVfsFile moveTo(VfsFile destination) throws java.io.IOException
java.io.IOExceptionvoid writeText(java.lang.String text)
throws java.io.IOException
text - text to write to the file.java.io.IOException - if unable to writejava.lang.String readText()
throws java.io.IOException
java.io.IOException - if unable to readjava.lang.String readTextRange(long start,
long end)
throws java.io.IOException
java.io.IOExceptionjava.util.List<java.lang.String> readTextAsLines()
throws java.io.IOException
java.io.IOException - if unable to readjava.util.List<java.lang.String> readTextAsLines(boolean trimLines)
throws java.io.IOException
java.io.IOException - if unable to readjava.util.List<java.lang.String> readTextAsLines(boolean trimLines,
boolean dropEmptyLines)
throws java.io.IOException
java.io.IOException - if unable to readvoid appendText(java.lang.String text)
throws java.io.IOException
text - text to appendjava.io.IOException - if unable to appendvoid writeBytes(byte[] bytes)
throws java.io.IOException
bytes - byte contents to writejava.io.IOException - if unable to writevoid appendBytes(byte[] bytes)
throws java.io.IOException
bytes - bytes to append to filejava.io.IOException - if unable to appendbyte[] readBytes()
throws java.io.IOException
java.io.IOException - if unable to readvoid textReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
replacements - list of strings, in alternating original1, replacement1, original2, replacement2, etc. orderjava.io.IOExceptionvoid textReplace(java.lang.String... replacements)
throws java.io.IOException
replacements - array or vararg list of strings, in alternating original1, replacement1, original2, replacement2, etc. orderjava.io.IOExceptionvoid regexReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
replacements - list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. orderjava.io.IOExceptionvoid regexReplace(java.lang.String... replacements)
throws java.io.IOException
replacements - array or vararg list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. orderjava.io.IOExceptionjava.io.InputStream createInputStream()
throws java.io.IOException
InputStream.close() when you are done with it. Note that
this stream is NOT buffered. This is usually a bad thing, unless you are
doing your own buffering or doing a single bulk read. So, don't use this
method unless you know what you're doing - use
createBufferedInputStream() instead.java.io.IOException - if the read failsjava.io.BufferedInputStream createBufferedInputStream()
throws java.io.IOException
OutputStream.close() when you are done with it. This
stream is buffered. This is usually a good thing. So, generally use this
method instead of createInputStream() unless you know what
you're doing.java.io.IOException - if the read failsjava.io.OutputStream createOutputStream()
throws java.io.IOException
OutputStream.close()).
Note that this stream is NOT buffered. This is usually a bad thing,
unless you are doing your own buffering or doing a bulk write. So, don't
use this method unless you know what you're doing - use
createBufferedOutputStream() instead.java.io.IOExceptionjava.io.BufferedOutputStream createBufferedOutputStream()
throws java.io.IOException
OutputStream.close()).
This stream is buffered, which is usually a good thing. You should
generally use this instead of createOutputStream() unless you
know what you're doing.java.io.IOExceptionjava.io.OutputStream createAppendingOutputStream()
throws java.io.IOException
OutputStream.close()).
Note that this stream is NOT buffered. This is usually a bad thing,
unless you are doing your own buffering or doing a bulk write. So, don't
use this method unless you know what you're doing - use
createAppendingBufferedOutputStream() instead.java.io.IOExceptionjava.io.BufferedOutputStream createAppendingBufferedOutputStream()
throws java.io.IOException
OutputStream.close()).
This stream is buffered, which is usually a good thing. You should
generally use this instead of createAppendingOutputStream()
unless you know what you're doing.java.io.IOExceptionjava.io.Reader createReader()
throws java.io.IOException
Reader.close()
when you are done with it. Note that this reader is NOT buffered. This is
usually a bad thing, unless you are doing your own buffering or doing a
single bulk read. So, don't use this method unless you know what you're
doing - use createBufferedReader() instead.java.io.IOException - if the read failsjava.io.BufferedReader createBufferedReader()
throws java.io.IOException
Reader.close() when you are done with it. This reader is
buffered. This is usually a good thing. So, generally use this method
instead of createReader() unless you know what you're doing.java.io.IOException - if the read failsjava.io.Writer createWriter()
throws java.io.IOException
Writer.close()). Note that
this writer is NOT buffered. This is usually a bad thing, unless you are
doing your own buffering or doing a bulk write. So, don't use this method
unless you know what you're doing - use createBufferedWriter()
instead.java.io.IOExceptionjava.io.BufferedWriter createBufferedWriter()
throws java.io.IOException
Writer.close()). This
writer is buffered, which is usually a good thing. You should generally
use this instead of createWriter() unless you know what you're
doing.java.io.IOExceptionjava.io.Writer createAppendingWriter()
throws java.io.IOException
Writer.close()).
Note that this writer is NOT buffered. This is usually a bad thing,
unless you are doing your own buffering or doing a bulk write. So, don't
use this method unless you know what you're doing - use
createAppendingBufferedWriter() instead.java.io.IOExceptionjava.io.BufferedWriter createAppendingBufferedWriter()
throws java.io.IOException
createAppendingWriter() unless you
know what you're doing.java.io.IOExceptionVfsRandomAccess createRandomAccess() throws java.io.IOException
java.io.IOException - if file can't be accessedDateAndTime getLastModified() throws java.io.IOException
new DateAndTime(getLastModifiedMillis()).getLastModified in interface VfsNodejava.io.IOExceptionvoid setLastModified(DateAndTime newLast) throws java.io.IOException
setLastModifiedMillis(newLast.getMillis()).setLastModified in interface VfsNodejava.io.IOExceptionlong getLastModifiedMillis()
throws java.io.IOException
getLastModified().getMillis().getLastModifiedMillis in interface VfsNodejava.io.IOExceptionvoid setLastModifiedMillis(long millis)
throws java.io.IOException
setLastModified(new DateAndTime(millis)).setLastModifiedMillis in interface VfsNodejava.io.IOExceptionlong checksum()
throws java.io.IOException
java.io.IOException