nl.uva.vlet.vfs
Class VFile

java.lang.Object
  extended by nl.uva.vlet.vrs.VNode
      extended by nl.uva.vlet.vfs.VFSNode
          extended by nl.uva.vlet.vfs.VFile
All Implemented Interfaces:
VACL, VEditable, VRandomAccessable, VRenamable, VStreamAccessable, VStreamReadable, VStreamWritable

public abstract class VFile
extends VFSNode
implements VRenamable, VEditable, VStreamAccessable, VRandomAccessable

The Virtual File Interface. An abstract representation of a File.

Note that an offset into a file can be of long size, but reading is limited to 'int' size.

See Also:
VDir

Field Summary
 
Fields inherited from class nl.uva.vlet.vfs.VFSNode
ATTR_ACCESS_TIME, ATTR_CREATION_TIME, ATTR_DATA_TYPE, ATTR_DIRNAME, ATTR_EXISTS, ATTR_GID, ATTR_GROUP, ATTR_ISDIR, ATTR_ISFILE, ATTR_ISHIDDEN, ATTR_ISREADABLE, ATTR_ISSOFTLINK, ATTR_ISWRITABLE, ATTR_LENGTH, ATTR_LINKTARGET, ATTR_MODIFICATION_TIME, ATTR_NRACLENTRIES, ATTR_NRCHILDS, ATTR_OWNER, ATTR_PARENT_DIRNAME, ATTR_PERMISSIONS_STRING, ATTR_RESOURCE, ATTR_UID, ATTR_UNIQUE, attributeNames, defaultStreamBufferSize
 
Fields inherited from class nl.uva.vlet.vrs.VNode
ATTR_CHARSET, ATTR_HOSTNAME, ATTR_ICON, ATTR_ISVLINK, ATTR_LOCATION, ATTR_MIMETYPE, ATTR_NAME, ATTR_PATH, ATTR_PORT, ATTR_SCHEME, ATTR_TYPE, location, vrsContext
 
Fields inherited from interface nl.uva.vlet.vfs.VACL
GROUP_ENTITY, PERM_ACCESSABLE, PERM_EXECUTABLE, PERM_READABLE, PERM_WRITABLE, USER_ENTITY, WORLD_ENTITY
 
Constructor Summary
VFile(VRSContext context, VRL vrl)
           
 
Method Summary
 VFile copyTo(VDir dest)
          Copy this file to another VFS location.
 VFile copyTo(VDir dest, java.lang.String newName)
          Copy this file to another VFS location.
 VFile copyTo(VRL destinationVrl)
          see copyToFile()
 VFile copyToDir(VRL destinationVrl)
          Copy this file to new destination location.
 VFile copyToFile(VRL destinationVrl)
          Copy this file to new destination location.
protected  VFile doCopyMoveTo(VFSTransfer transfer, VDir dest, java.lang.String optNewName, boolean isMove)
          Default implementation to do actual copy/move.
protected  VFile downloadTo(VFSTransfer transfer, VDir localDir, java.lang.String optNewName, boolean isMove)
          Default implemenation to download files, sub classes are encouraged to override this method if they have their own (better) methods.
 byte[] getContents()
          Read the whole contents and return in byte array.
 byte[] getContents(int len)
          Reads first len bytes into byte array
 byte[] getContents(long offset, int len)
          Reads first len bytes into byte array
 java.lang.String getContentsAsString()
           
 java.lang.String getContentsAsString(java.lang.String charSet)
          Read contents and return as single String.
 VRL getHelp()
          Returns simple text file or complete HTML page.
abstract  long getLength()
          Return length of this resource object
 java.lang.String getType()
          Returns type String of this VNode
 boolean isDir()
          Implementation of VFSNode.isDir().
 boolean isFile()
          Needed by VFSNode interface.
 VFile moveTo(VDir dest)
          Moves file from one VFS location to another.
 VFile moveTo(VDir dest, java.lang.String newName)
          Moves file from one VFS location to another.
 int read(byte[] buffer, int nrOfBytes)
           
 int read(byte[] buffer, int bufferOffset, int nrOfBytes)
           
 int read(long offset, byte[] buffer, int bufferOffset, int nrOfBytes)
          Read from a (remote) VFile.
Method tries to use the RandomAccessable interface or the InputStream from VStreamReasable to read from.
 void setContents(byte[] bytes)
          Replace or create File contents with data from the bytes array.
 void setContents(java.lang.String contents)
          Set contents using specified String.
 void setContents(java.lang.String contents, java.lang.String encoding)
          Set contents using specified String and encoding.
protected static VFile streamCopyMove(VFSTransfer transfer, VFile sourceFile, VDir destDir, java.lang.String optNewName, boolean isMove)
          This is the default way to copy file, by reading from the source file and writing it to a remote file.
 int streamRead(long offset, byte[] buffer, int bufferOffset, int nrOfBytes)
          use InputStream to read bytes, not the RandomAcces method readBytes.
 void streamWrite(byte[] buffer, int bufferOffset, int nrOfBytes)
          Uses OutputStream to write to method i.s.o.
 void write(byte[] buffer, int nrOfBytes)
           
 void write(byte[] buffer, int bufferOffset, int nrOfBytes)
           
 void write(long offset, byte[] buffer, int bufferOffset, int nrOfBytes)
          Write to VFile, note that not all implementations of VFile can write to (Remote) Files.
Use isRandomAccessable() first to determine whether this file can be randomly written to.
 
Methods inherited from class nl.uva.vlet.vfs.VFSNode
asyncCopyMoveTo, create, createACLRecord, createTransfer, createTransferTo, deleteACLEntity, exists, getACL, getACLEntities, getAttribute, getAttributeNames, getLinkTarget, getLinkTargetVRL, getModificationTime, getParent, getParents, getPath, getPermissionsString, getRoot, getTranferInfo, isDeletable, isEditable, isHidden, isLink, isLocal, isRandomAccessable, isReadable, isRenamable, isWritable, returnAsArray, setACL, setAttribute, setAttributes, startCopyMoveTo, startCopyMoveTo
 
Methods inherited from class nl.uva.vlet.vrs.VNode
compareTo, getAttributes, getAttributes, getAttributeSet, getBasename, getCharSet, getHostname, getIconURL, getID, getLocation, getMimeType, getName, getPath, getPort, getScheme, getServerAttributes, getURI, getVRL, getVRSContext, isComposite, isVirtual, isVLink, mergedGetAttributes, setLocation, setVRL, toLinkNode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface nl.uva.vlet.vrs.VRenamable
isRenamable, renameTo
 
Methods inherited from interface nl.uva.vlet.vrs.VEditable
delete, isDeletable, isEditable, setAttribute, setAttributes
 
Methods inherited from interface nl.uva.vlet.vrs.VStreamReadable
getInputStream
 
Methods inherited from interface nl.uva.vlet.vrs.VStreamWritable
getOutputStream
 
Methods inherited from interface nl.uva.vlet.vrs.VRandomAccessable
readBytes, setLengthToZero, writeBytes
 

Constructor Detail

VFile

public VFile(VRSContext context,
             VRL vrl)
Method Detail

getType

public java.lang.String getType()
Returns type String of this VNode

Specified by:
getType in class VNode

getHelp

public VRL getHelp()
Description copied from class: VNode
Returns simple text file or complete HTML page. Method should point to installed documentation. Default is to return help about this type.

Overrides:
getHelp in class VNode

isFile

public boolean isFile()
Needed by VFSNode interface.

Specified by:
isFile in class VFSNode
Returns:
true
See Also:
VFSNode.isFile()

isDir

public boolean isDir()
Implementation of VFSNode.isDir().

Specified by:
isDir in class VFSNode
See Also:
VFSNode.isDir()

getContents

public byte[] getContents()
                   throws VlException
Read the whole contents and return in byte array. Current implementation is to let readBytes to return an array this might have to change to some ByteBuffer placeholder class.

Throws:
VlException

getContents

public byte[] getContents(int len)
                   throws VlException
Reads first len bytes into byte array

Throws:
VlException

getContents

public byte[] getContents(long offset,
                          int len)
                   throws VlException
Reads first len bytes into byte array

Throws:
VlException

getContentsAsString

public java.lang.String getContentsAsString(java.lang.String charSet)
                                     throws VlException
Read contents and return as single String. This method will fail if the VFile doesn't implement the VStreamReadable interface !

Throws:
VlException

getContentsAsString

public java.lang.String getContentsAsString()
                                     throws VlException
Throws:
VlException

copyTo

public final VFile copyTo(VRL destinationVrl)
                   throws VlException
see copyToFile()

Throws:
VlException

copyToFile

public final VFile copyToFile(VRL destinationVrl)
                       throws VlException
Copy this file to new destination location. The destinationVrl specifies the full path of the new File.

Parameters:
destinationVrl -
Returns:
Throws:
VlException

copyToDir

public final VFile copyToDir(VRL destinationVrl)
                      throws VlException
Copy this file to new destination location. The destinationVrl is the parent directory of the destination file.

Parameters:
destinationVrl -
Returns:
Throws:
VlException

copyTo

public final VFile copyTo(VDir dest)
                   throws VlException
Copy this file to another VFS location. is called by VFSClient.copyFile.

Specified by:
copyTo in class VFSNode
Parameters:
b -
Throws:
VlException
See Also:
VFS#cmoveFile(VFile, VDir, boolean)

copyTo

public final VFile copyTo(VDir dest,
                          java.lang.String newName)
                   throws VlException
Copy this file to another VFS location. is called by VFSClient.copyFile.

Specified by:
copyTo in class VFSNode
Parameters:
b -
Throws:
VlException
See Also:
VFS#cmoveFile(VFile, VDir, boolean)

moveTo

public final VFile moveTo(VDir dest)
                   throws VlException
Moves file from one VFS location to another.

Specified by:
moveTo in class VFSNode
Throws:
VlException
See Also:
#doCopyMoveTo(VDir, boolean)

moveTo

public final VFile moveTo(VDir dest,
                          java.lang.String newName)
                   throws VlException
Moves file from one VFS location to another.

Specified by:
moveTo in class VFSNode
Throws:
VlException
See Also:
#doCopyMoveTo(VDir, boolean)

write

public void write(long offset,
                  byte[] buffer,
                  int bufferOffset,
                  int nrOfBytes)
           throws VlException
Write to VFile, note that not all implementations of VFile can write to (Remote) Files.
Use isRandomAccessable() first to determine whether this file can be randomly written to.

Throws:
VlException
See Also:
read, VRandomAccessable

write

public void write(byte[] buffer,
                  int bufferOffset,
                  int nrOfBytes)
           throws VlException
Throws:
VlException

write

public void write(byte[] buffer,
                  int nrOfBytes)
           throws VlException
Throws:
VlException

streamWrite

public void streamWrite(byte[] buffer,
                        int bufferOffset,
                        int nrOfBytes)
                 throws VlException
Uses OutputStream to write to method i.s.o. RandomAccesFile. For some implementation this is faster. No offset is supported.

Throws:
VlException

setContents

public void setContents(java.lang.String contents,
                        java.lang.String encoding)
                 throws VlException
Set contents using specified String and encoding.

Parameters:
contents - : new Contents
encoding - : charset to use
Throws:
VlException - if contents can not be set somehow

read

public int read(long offset,
                byte[] buffer,
                int bufferOffset,
                int nrOfBytes)
         throws VlException
Read from a (remote) VFile.
Method tries to use the RandomAccessable interface or the InputStream from VStreamReasable to read from.

Parameters:
offset -
nrOfBytes -
bufferOffset -
buffer -
Returns:
Throws:
VlException - if interface does not support remote read access.

read

public int read(byte[] buffer,
                int bufferOffset,
                int nrOfBytes)
         throws VlException
Throws:
VlException
See Also:
read(long offset, byte buffer[],int bufferOffset,int nrOfBytes)

read

public int read(byte[] buffer,
                int nrOfBytes)
         throws VlException
Throws:
VlException
See Also:
read(long offset, byte buffer[],int bufferOffset,int nrOfBytes)

streamRead

public int streamRead(long offset,
                      byte[] buffer,
                      int bufferOffset,
                      int nrOfBytes)
               throws VlException
use InputStream to read bytes, not the RandomAcces method readBytes. For some implemenations this is faster.

Throws:
VlException

setContents

public void setContents(byte[] bytes)
                 throws VlException
Replace or create File contents with data from the bytes array. The new file length will match the byte array lenth thus optionally truncating or extend an existing file.

Throws:
VlException

setContents

public void setContents(java.lang.String contents)
                 throws VlException
Set contents using specified String. Note that the default encoding format is 'UTF-8'.

Parameters:
contents - : new Contents String
Throws:
VlException
See Also:
to specify the coding

doCopyMoveTo

protected VFile doCopyMoveTo(VFSTransfer transfer,
                             VDir dest,
                             java.lang.String optNewName,
                             boolean isMove)
                      throws VlException
Default implementation to do actual copy/move. Decides whether to upload,download or perform a stream copy, depending on whether this file or the remote one or nether is a local file.
 
  This File   Remote Destination    isMove  method 
   local       remote                -       VDir.uploadFile 
   remote      local                 -       VFile.downloadTo
   [Source has same server as dest]  true    renameTo
    -           -                    -       VFile.streamcopy
 
Implementations can choose wether to override this method or the one of the upload/download methods

Parameters:
transfer -
Throws:
VlException
See Also:
moveTo(VDir), copyTo(VDir), VDir.uploadFile(VFile), VFile.downloadTo(VDir,String,boolean)

downloadTo

protected VFile downloadTo(VFSTransfer transfer,
                           VDir localDir,
                           java.lang.String optNewName,
                           boolean isMove)
                    throws VlException
Default implemenation to download files, sub classes are encouraged to override this method if they have their own (better) methods. It's counterpart 'upload' is found in VDir.

Throws:
VlException
See Also:
VDir.uploadFile, VDir.uploadDir

streamCopyMove

protected static VFile streamCopyMove(VFSTransfer transfer,
                                      VFile sourceFile,
                                      VDir destDir,
                                      java.lang.String optNewName,
                                      boolean isMove)
                               throws VlException
This is the default way to copy file, by reading from the source file and writing it to a remote file. This method uses VStreamReadable and VStreamWritable interfaces to copy the data.

TODO: make it multithreaded so progress statistics can be kept.

Parameters:
transfer -
Throws:
VlException
See Also:
VStreamWritable, VStreamReadable

getLength

public abstract long getLength()
                        throws VlException
Return length of this resource object

Throws:
VlException