public abstract class AbstractVfsFile extends java.lang.Object implements VfsFile
Most implementations of VfsFile should extend this class.
A minimal set of methods has been declared abstract. All other methods are derived from these with default implementations. For example, the various buffered forms of the create methods simply add a buffered wrapper to the plain create (e.g. createBufferedInputStream() returns a new BufferedInputStream wrapped around the results of createInputStream()). Also, the createReader/createWriter methods simply apply wrappers to the results of createInputStream/createOutputStream. Feel free to override these default implementations if a more efficient method is available (e.g. if you're already getting a BufferedInputStream).
The default createInputStream() and createOutputStream() automatically wrap the results in a ConnectionTrackingInputStream or ConnectionTrackingOutputStream - if you supply your own implementation you should do the same.
Copyright 2006-2012 Partner Software, Inc.
| Constructor and Description |
|---|
AbstractVfsFile(Vfs vfs,
Path path)
Create a new AbstractVfsFile with the given vfs and path.
|
| 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.
|
protected abstract java.io.OutputStream |
createAppendingOutputStreamImp() |
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.
|
protected abstract java.io.InputStream |
createInputStreamImp() |
java.io.OutputStream |
createOutputStream()
Creates an output stream to write to the file.
|
protected abstract java.io.OutputStream |
createOutputStreamImp() |
abstract 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.
|
boolean |
equals(java.lang.Object nother) |
abstract boolean |
exists()
Whether the Vfs node exists.
|
Path |
getAbsolutePath()
The absolute path to the Vfs node.
|
java.lang.String |
getBaseName()
Base name of node; this is the part before the '.' if there's a file
extension.
|
VfsDirectory |
getDirectory()
The VfsDirectory this node is in, or null if it is the root directory.
|
java.lang.String |
getExtension()
File extension (the part after the '.' in most file names; includes the
'.').
|
DateAndTime |
getLastModified()
Returns the date and time the file was last modified.
|
abstract long |
getLastModifiedMillis()
Returns the timestamp in milliseconds that the file was last modified.
|
java.lang.String |
getName()
Bare name of node.
|
Path |
getPath()
The path to the Vfs node.
|
Vfs |
getVfs()
The Vfs this node is in.
|
int |
hashCode() |
boolean |
isBackup()
True if the file is a backup file - commonly this is based on file name patterns like *~ or *.bak.
|
boolean |
isHidden()
True if the file is a hidden file - commonly this is based on the file name starting with a ".".
|
abstract void |
make()
Creates the node and any ancestor directories needed to contain it.
|
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.
|
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.
|
abstract void |
setLastModifiedMillis(long millis)
If possible, sets the date and time the file was last modified in
milliseconds.
|
abstract 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.
|
java.lang.String |
toString() |
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.
|
public abstract boolean exists()
throws java.io.IOException
VfsNodeVfsNode.make() to create the node if it does not exist.public abstract void make()
throws java.io.IOException
VfsNodepublic abstract long size()
throws java.io.IOException
protected abstract java.io.InputStream createInputStreamImp()
throws java.io.IOException
java.io.IOExceptionprotected abstract java.io.OutputStream createOutputStreamImp()
throws java.io.IOException
java.io.IOExceptionprotected abstract java.io.OutputStream createAppendingOutputStreamImp()
throws java.io.IOException
java.io.IOExceptionpublic abstract VfsRandomAccess createRandomAccess() throws java.io.IOException
VfsFilecreateRandomAccess in interface VfsFilejava.io.IOException - if file can't be accessedpublic abstract long getLastModifiedMillis()
throws java.io.IOException
VfsFilegetLastModified().getMillis().getLastModifiedMillis in interface VfsFilegetLastModifiedMillis in interface VfsNodejava.io.IOExceptionpublic abstract void setLastModifiedMillis(long millis)
throws java.io.IOException
VfsFilesetLastModified(new DateAndTime(millis)).setLastModifiedMillis in interface VfsFilesetLastModifiedMillis in interface VfsNodejava.io.IOExceptionpublic VfsFile withExtension(java.lang.String extension)
withExtension in interface VfsFilepublic java.io.Reader createReader()
throws java.io.IOException
VfsFileReader.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 VfsFile.createBufferedReader() instead.createReader in interface VfsFilejava.io.IOException - if the read failspublic java.io.Writer createWriter()
throws java.io.IOException
VfsFileWriter.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 VfsFile.createBufferedWriter()
instead.createWriter in interface VfsFilejava.io.IOExceptionpublic java.io.Writer createAppendingWriter()
throws java.io.IOException
VfsFileWriter.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
VfsFile.createAppendingBufferedWriter() instead.createAppendingWriter in interface VfsFilejava.io.IOExceptionpublic VfsFile renameTo(java.lang.String name) throws java.io.IOException
VfsFilepublic VfsFile copyTo(Path newPath) throws java.io.IOException
VfsFilepublic java.io.InputStream createInputStream()
throws java.io.IOException
VfsFileInputStream.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
VfsFile.createBufferedInputStream() instead.createInputStream in interface VfsFilejava.io.IOException - if the read failspublic java.io.OutputStream createOutputStream()
throws java.io.IOException
VfsFileOutputStream.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
VfsFile.createBufferedOutputStream() instead.createOutputStream in interface VfsFilejava.io.IOExceptionpublic java.io.OutputStream createAppendingOutputStream()
throws java.io.IOException
VfsFileOutputStream.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
VfsFile.createAppendingBufferedOutputStream() instead.createAppendingOutputStream in interface VfsFilejava.io.IOExceptionpublic VfsFile copyTo(VfsFile destination) throws java.io.IOException
VfsFilepublic VfsFile moveTo(Path newPath) throws java.io.IOException
VfsFilepublic VfsFile moveTo(VfsFile destination) throws java.io.IOException
VfsFilepublic long checksum()
throws java.io.IOException
VfsFilepublic void writeText(java.lang.String text)
throws java.io.IOException
VfsFilepublic java.lang.String readText()
throws java.io.IOException
VfsFilepublic java.lang.String readTextRange(long start,
long end)
throws java.io.IOException
VfsFilereadTextRange in interface VfsFilejava.io.IOExceptionpublic java.util.List<java.lang.String> readTextAsLines()
throws java.io.IOException
VfsFilereadTextAsLines in interface VfsFilejava.io.IOException - if unable to readpublic java.util.List<java.lang.String> readTextAsLines(boolean trimLines)
throws java.io.IOException
VfsFilereadTextAsLines in interface VfsFilejava.io.IOException - if unable to readpublic java.util.List<java.lang.String> readTextAsLines(boolean trimLines,
boolean dropEmptyLines)
throws java.io.IOException
VfsFilereadTextAsLines in interface VfsFilejava.io.IOException - if unable to readpublic void appendText(java.lang.String text)
throws java.io.IOException
VfsFileappendText in interface VfsFiletext - text to appendjava.io.IOException - if unable to appendpublic void writeBytes(byte[] bytes)
throws java.io.IOException
VfsFilewriteBytes in interface VfsFilebytes - byte contents to writejava.io.IOException - if unable to writepublic void appendBytes(byte[] bytes)
throws java.io.IOException
VfsFileappendBytes in interface VfsFilebytes - bytes to append to filejava.io.IOException - if unable to appendpublic byte[] readBytes()
throws java.io.IOException
VfsFilepublic void textReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
VfsFiletextReplace in interface VfsFilereplacements - list of strings, in alternating original1, replacement1, original2, replacement2, etc. orderjava.io.IOExceptionpublic void textReplace(java.lang.String... replacements)
throws java.io.IOException
VfsFiletextReplace in interface VfsFilereplacements - array or vararg list of strings, in alternating original1, replacement1, original2, replacement2, etc. orderjava.io.IOExceptionpublic void regexReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
VfsFileregexReplace in interface VfsFilereplacements - list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. orderjava.io.IOExceptionpublic void regexReplace(java.lang.String... replacements)
throws java.io.IOException
VfsFileregexReplace in interface VfsFilereplacements - array or vararg list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. orderjava.io.IOExceptionpublic java.io.BufferedInputStream createBufferedInputStream()
throws java.io.IOException
VfsFileOutputStream.close() when you are done with it. This
stream is buffered. This is usually a good thing. So, generally use this
method instead of VfsFile.createInputStream() unless you know what
you're doing.createBufferedInputStream in interface VfsFilejava.io.IOException - if the read failspublic java.io.BufferedOutputStream createBufferedOutputStream()
throws java.io.IOException
VfsFileOutputStream.close()).
This stream is buffered, which is usually a good thing. You should
generally use this instead of VfsFile.createOutputStream() unless you
know what you're doing.createBufferedOutputStream in interface VfsFilejava.io.IOExceptionpublic java.io.BufferedOutputStream createAppendingBufferedOutputStream()
throws java.io.IOException
VfsFileOutputStream.close()).
This stream is buffered, which is usually a good thing. You should
generally use this instead of VfsFile.createAppendingOutputStream()
unless you know what you're doing.createAppendingBufferedOutputStream in interface VfsFilejava.io.IOExceptionpublic java.io.BufferedReader createBufferedReader()
throws java.io.IOException
VfsFileReader.close() when you are done with it. This reader is
buffered. This is usually a good thing. So, generally use this method
instead of VfsFile.createReader() unless you know what you're doing.createBufferedReader in interface VfsFilejava.io.IOException - if the read failspublic java.io.BufferedWriter createBufferedWriter()
throws java.io.IOException
VfsFileWriter.close()). This
writer is buffered, which is usually a good thing. You should generally
use this instead of VfsFile.createWriter() unless you know what you're
doing.createBufferedWriter in interface VfsFilejava.io.IOExceptionpublic java.io.BufferedWriter createAppendingBufferedWriter()
throws java.io.IOException
VfsFileVfsFile.createAppendingWriter() unless you
know what you're doing.createAppendingBufferedWriter in interface VfsFilejava.io.IOExceptionpublic Path getAbsolutePath()
VfsNodegetAbsolutePath in interface VfsNodepublic java.lang.String getName()
VfsNodepublic java.lang.String getBaseName()
VfsNodegetBaseName in interface VfsNodepublic java.lang.String getExtension()
VfsNodegetExtension in interface VfsNodepublic DateAndTime getLastModified() throws java.io.IOException
VfsFilenew DateAndTime(getLastModifiedMillis()).getLastModified in interface VfsFilegetLastModified in interface VfsNodejava.io.IOExceptionpublic void setLastModified(DateAndTime newLast) throws java.io.IOException
VfsFilesetLastModifiedMillis(newLast.getMillis()).setLastModified in interface VfsFilesetLastModified in interface VfsNodejava.io.IOExceptionpublic VfsDirectory getDirectory()
VfsNodegetDirectory in interface VfsNodepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isBackup()
VfsNodepublic boolean isHidden()
VfsNodepublic boolean equals(java.lang.Object nother)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object