|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuk.ac.rdg.resc.jstyx.server.StyxFile
uk.ac.rdg.resc.jstyx.server.FileOnDisk
public class FileOnDisk
Class representing a file on a hard drive. Note that creating a new instance of this class does not create an actual new file on the hard disk; it simply creates a wrapper for an existing file. This class opens a new Input/OutputStream every time a read/write message arrives, so it is probably not very efficient (but this was the simplest way to implement reliably).
| Field Summary | |
|---|---|
protected boolean |
eofWritten
|
protected java.io.File |
file
|
protected boolean |
mustExist
|
| Fields inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile |
|---|
auth, directory, lastModifiedTime, name, parent |
| Constructor Summary | |
|---|---|
FileOnDisk(java.io.File file)
Creates a new FileOnDisk whose name is the same as that of (the last part of) the underlying file (i.e. |
|
FileOnDisk(java.io.File file,
boolean mustExist)
Creates a FileOnDisk with default permissions (0666). |
|
FileOnDisk(java.lang.String filepath)
Creates a new FileOnDisk that wraps the file at the given path |
|
FileOnDisk(java.lang.String name,
java.io.File file)
Creates a FileOnDisk with the default permissions (0666, rw-rw-rw-) |
|
FileOnDisk(java.lang.String name,
java.io.File file,
int permissions,
boolean mustExist)
|
|
| Method Summary | |
|---|---|
protected void |
delete()
Closes the open FileChannel and removes the underlying file from the disk |
static StyxFile |
getFileOrDirectoryOnDisk(java.io.File file)
Gets a StyxFile that wraps the given java.io.File. |
ULong |
getLength()
|
void |
read(StyxFileClient client,
long offset,
int count,
int tag)
Reads from the underlying java.io.File. |
boolean |
receivedEOF()
|
void |
refresh()
Reads all metadata from underlying disk file |
void |
write(StyxFileClient client,
long offset,
int count,
org.apache.mina.common.ByteBuffer data,
boolean truncate,
int tag)
Writes data to the underlying java.io.File. |
| Methods inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile |
|---|
addChangeListener, addClient, checkSetLastModifiedTime, checkSetLength, checkSetMode, checkSetName, clientConnected, clientDisconnected, contentsChanged, fireContentsChanged, getClient, getDirEntry, getFullPath, getGroup, getName, getNumClients, getOwner, getParent, getPermissions, getQid, getVersion, incrementVersion, isAppendOnly, isAuth, isDirectory, isExclusive, processAndReplyRead, processAndReplyRead, processAndReplyRead, remove, removeChangeListener, removeClient, rename, replyRead, replyRead, replyRead, replyRead, replyRead, replyWrite, setLastAccessTime, setLastModified, setLength, setMode, setName, setPermissions, setReadOnly |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.io.File file
protected boolean mustExist
protected boolean eofWritten
| Constructor Detail |
|---|
public FileOnDisk(java.lang.String filepath)
throws StyxException
StyxException
public FileOnDisk(java.io.File file)
throws StyxException
file - The java.io.File which this represents
StyxException - if the java.io.File does not exist
public FileOnDisk(java.lang.String name,
java.io.File file)
throws StyxException
name - The name of this file as it will appear in the namespacefile - The java.io.File which this represents
StyxException - if the java.io.File does not exist
public FileOnDisk(java.io.File file,
boolean mustExist)
throws StyxException
file - The java.io.File which this representsmustExist - If this is true, then an exception will be thrown by this
constructor if the underlying java.io.File does not exist. Furthermore,
if the File is deleted, the FileOnDisk will be removed from the namespace.
If this is set false, a non-existent File will be represented as a
zero-length read-only FileOnDisk in the namespace.
StyxException - if the java.io.File does not exist and mustExist=true
public FileOnDisk(java.lang.String name,
java.io.File file,
int permissions,
boolean mustExist)
throws StyxException
name - The name of this file as it will appear in the namespacefile - The java.io.File which this representspermissions - the permissions of the filemustExist - If this is true, then an exception will be thrown by this
constructor if the underlying java.io.File does not exist. Furthermore,
if the File is deleted, the FileOnDisk will be removed from the namespace.
If this is set false, a non-existent File will be represented as a
zero-length read-only FileOnDisk in the namespace.
StyxException - if the java.io.File does not exist and mustExist=true| Method Detail |
|---|
public static StyxFile getFileOrDirectoryOnDisk(java.io.File file)
throws StyxException
StyxException - if the File does not exist
public void read(StyxFileClient client,
long offset,
int count,
int tag)
throws StyxException
read in class StyxFileclient - The client that is performing the readoffset - The point in the file at which to start readingcount - The maximum number of bytes to readtag - The tag of the incoming Tread message (this is needed when
calling readReply())
StyxException
public void write(StyxFileClient client,
long offset,
int count,
org.apache.mina.common.ByteBuffer data,
boolean truncate,
int tag)
throws StyxException
mustExist is true, this throws a StyxException. If the File
does not exist and mustExist is false.
write in class StyxFileclient - The client that is performing the write operationoffset - The place in the file where the new data will be addedcount - The number of bytes to writedata - The data to write. The position and limit of this ByteBuffer
will be set correctly, but subclasses should note that the position might
not be zero.truncate - If this is true the file will be truncated at the end of
the new datatag - The tag of the incoming Twrite message (this is needed when
calling writeReply())
StyxExceptionpublic void refresh()
refresh in class StyxFilepublic ULong getLength()
getLength in class StyxFilepublic boolean receivedEOF()
protected void delete()
delete in class StyxFile
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||