|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.io.vfs.AbstractVfsFile
public abstract class AbstractVfsFile
A standard abstract implementation of com.partnersoft.io.VfsFile. Includes implementations of the various convenience methods derived from the essential methods, and provides the vfs and path properties.
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).
Copyright 2006-2007 Partner Software, Inc.
| Constructor Summary | |
|---|---|
AbstractVfsFile(Vfs vfs,
Path path)
Create a new AbstractVfsFile with the given vfs and path. |
|
| Method Summary | |
|---|---|
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. |
abstract 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. |
abstract java.io.InputStream |
createInputStream()
Creates an input stream to read from the file. |
abstract java.io.OutputStream |
createOutputStream()
Creates an output stream to write to the file. |
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. |
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.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. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.partnersoft.io.vfs.VfsFile |
|---|
remove |
| Methods inherited from interface com.partnersoft.io.vfs.VfsNode |
|---|
getUri, getUrl, toFile |
| Constructor Detail |
|---|
public AbstractVfsFile(Vfs vfs,
Path path)
vfs - Vfs file is in.path - path to file in Vfs.| Method Detail |
|---|
public abstract boolean exists()
throws java.io.IOException
VfsNodeVfsNode.make() to create the node if it does not exist.
exists in interface VfsNodejava.io.IOException - if it can't tell for some reason.
public abstract void make()
throws java.io.IOException
VfsNode
make in interface VfsNodejava.io.IOException - if it can't.
public abstract long size()
throws java.io.IOException
size in interface VfsFilejava.io.IOException
public abstract 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 fails
public abstract 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.IOException
public abstract 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.IOException
public abstract VfsRandomAccess createRandomAccess()
throws java.io.IOException
VfsFile
createRandomAccess in interface VfsFilejava.io.IOException - if file can't be accessed
public abstract long getLastModifiedMillis()
throws java.io.IOException
VfsFilegetLastModified().getMillis().
getLastModifiedMillis in interface VfsFilejava.io.IOException
public abstract void setLastModifiedMillis(long millis)
throws java.io.IOException
VfsFilesetLastModified(new DateAndTime(millis)).
setLastModifiedMillis in interface VfsFilejava.io.IOExceptionpublic VfsFile withExtension(java.lang.String extension)
withExtension in interface VfsFile
public 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 fails
public 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.IOException
public 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.IOException
public VfsFile renameTo(java.lang.String name)
throws java.io.IOException
VfsFile
renameTo in interface VfsFilejava.io.IOException
public VfsFile copyTo(Path newPath)
throws java.io.IOException
VfsFile
copyTo in interface VfsFilejava.io.IOException
public VfsFile copyTo(VfsFile destination)
throws java.io.IOException
VfsFile
copyTo in interface VfsFilejava.io.IOException
public VfsFile moveTo(Path newPath)
throws java.io.IOException
VfsFile
moveTo in interface VfsFilejava.io.IOException
public VfsFile moveTo(VfsFile destination)
throws java.io.IOException
VfsFile
moveTo in interface VfsFilejava.io.IOException
public long checksum()
throws java.io.IOException
VfsFile
checksum in interface VfsFilejava.io.IOException
public void writeText(java.lang.String text)
throws java.io.IOException
VfsFile
writeText in interface VfsFiletext - text to write to the file.
java.io.IOException - if unable to write
public java.lang.String readText()
throws java.io.IOException
VfsFile
readText in interface VfsFilejava.io.IOException - if unable to read
public java.lang.String readTextRange(long start,
long end)
throws java.io.IOException
VfsFile
readTextRange in interface VfsFilejava.io.IOException
public java.util.List<java.lang.String> readTextAsLines()
throws java.io.IOException
VfsFile
readTextAsLines in interface VfsFilejava.io.IOException - if unable to read
public void appendText(java.lang.String text)
throws java.io.IOException
VfsFile
appendText in interface VfsFiletext - text to append
java.io.IOException - if unable to append
public void writeBytes(byte[] bytes)
throws java.io.IOException
VfsFile
writeBytes in interface VfsFilebytes - byte contents to write
java.io.IOException - if unable to write
public void appendBytes(byte[] bytes)
throws java.io.IOException
VfsFile
appendBytes in interface VfsFilebytes - bytes to append to file
java.io.IOException - if unable to append
public byte[] readBytes()
throws java.io.IOException
VfsFile
readBytes in interface VfsFilejava.io.IOException - if unable to read
public void textReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
VfsFile
textReplace in interface VfsFilereplacements - list of strings, in alternating original1, replacement1, original2, replacement2, etc. order
java.io.IOException
public void textReplace(java.lang.String... replacements)
throws java.io.IOException
VfsFile
textReplace in interface VfsFilereplacements - array or vararg list of strings, in alternating original1, replacement1, original2, replacement2, etc. order
java.io.IOException
public void regexReplace(java.util.List<java.lang.String> replacements)
throws java.io.IOException
VfsFile
regexReplace in interface VfsFilereplacements - list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. order
java.io.IOException
public void regexReplace(java.lang.String... replacements)
throws java.io.IOException
VfsFile
regexReplace in interface VfsFilereplacements - array or vararg list of strings, in alternating regex1, replacement1, regex2, replacement2, etc. order
java.io.IOException
public 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 fails
public 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.IOException
public 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.IOException
public 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 fails
public 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.IOException
public java.io.BufferedWriter createAppendingBufferedWriter()
throws java.io.IOException
VfsFileVfsFile.createAppendingWriter() unless you
know what you're doing.
createAppendingBufferedWriter in interface VfsFilejava.io.IOExceptionpublic Path getPath()
VfsNode
getPath in interface VfsNodepublic Path getAbsolutePath()
VfsNode
getAbsolutePath in interface VfsNodepublic Vfs getVfs()
VfsNode
getVfs in interface VfsNodepublic java.lang.String getName()
VfsNode
getName in interface VfsNodepublic java.lang.String getBaseName()
VfsNode
getBaseName in interface VfsNodepublic java.lang.String getExtension()
VfsNode
getExtension in interface VfsNode
public DateAndTime getLastModified()
throws java.io.IOException
VfsFilenew DateAndTime(getLastModifiedMillis()).
getLastModified in interface VfsFilejava.io.IOException
public void setLastModified(DateAndTime newLast)
throws java.io.IOException
VfsFilesetLastModifiedMillis(newLast.getMillis()).
setLastModified in interface VfsFilejava.io.IOExceptionpublic VfsDirectory getDirectory()
VfsNode
getDirectory in interface VfsNodepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isBackup()
VfsNode
isBackup in interface VfsNodepublic boolean isHidden()
VfsNode
isHidden in interface VfsNodepublic boolean equals(java.lang.Object nother)
equals in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||