net.kano.joscar.rvproto.getfile
Class GetFileEntry

java.lang.Object
  extended byGetFileEntry
All Implemented Interfaces:
LiveWritable

public class GetFileEntry
extends java.lang.Object
implements LiveWritable

A data structure representing a single file or directory in a "Get File" directory listing.


Field Summary
static long FLAG_DIR
          A flag indicating that a file entry is a directory.
 
Constructor Summary
GetFileEntry(java.io.File file)
          Creates a new Get File directory listing entry with the properties of the given file.
GetFileEntry(SegmentedFilename filename, java.io.File file)
          Creates a new Get File directory listing entry with the properties of the given file and with the given name.
GetFileEntry(SegmentedFilename filename, long filesize, long lastmod, long flags)
          Creates a new Get File directory list entry with the given properties.
 
Method Summary
 SegmentedFilename getFilename()
          Returns the filename in this directory listing entry, or null if none is present.
 long getFileSize()
          Returns the file size in this directory listing entry, or -1 if none is present.
 long getFlags()
          Returns a the set of flags in this directory listing entry.
 long getLastmod()
          Returns the last modification date in this directory listing entry, in seconds since the unix epoch.
 int getTotalTlvCount()
          Returns the total number of TLV's read in constructing this entry object.
static GetFileEntry readEntry(Tlv[] tlvs, int offset)
          Reads a Get File directory list entry from the given list of TLV's.
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes a representation of this object to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLAG_DIR

public static final long FLAG_DIR
A flag indicating that a file entry is a directory.

See Also:
Constant Field Values
Constructor Detail

GetFileEntry

public GetFileEntry(java.io.File file)
Creates a new Get File directory listing entry with the properties of the given file.

Using this constructor is equivalent to using new GetFileEntry(SegmentedFilename.fromNativeFilename(file.getName()), file).

Parameters:
file - the file whose properties should be used in this entry

GetFileEntry

public GetFileEntry(SegmentedFilename filename,
                    java.io.File file)
Creates a new Get File directory listing entry with the properties of the given file and with the given name.

Using this constructor is equivalent to using new GetFileEntry(filename, file.lastModified() / 1000, file.isDirectory() ? FLAG_DIR : 0).

Parameters:
filename - a filename to use in this entry
file - a file whose properties will be used for this entry

GetFileEntry

public GetFileEntry(SegmentedFilename filename,
                    long filesize,
                    long lastmod,
                    long flags)
Creates a new Get File directory list entry with the given properties. Note that any of this method's arguments may be null or -1 (depending on argument type) to indicate that that field should not be present in the created entry.

Parameters:
filename - the name of the file
filesize - the size of the file
lastmod - the last modification date of the file, in seconds since the unix epoch
flags - a set of bit flags describing this file, like FLAG_DIR or 0
Method Detail

readEntry

public static final GetFileEntry readEntry(Tlv[] tlvs,
                                           int offset)
Reads a Get File directory list entry from the given list of TLV's. Note that the total number of TLV's read can be obtained by calling the returned GetFileEntry's getTotalTlvCount() method.

Parameters:
tlvs - a list of TLV's containing a Get File directory list entry
offset - the index of the first TLV in the given array from which the file entry TLV's should be read
Returns:
a Get File directory list entry read from the given list of TLV's

getFilename

public final SegmentedFilename getFilename()
Returns the filename in this directory listing entry, or null if none is present.

Returns:
this entry's filename

getFileSize

public final long getFileSize()
Returns the file size in this directory listing entry, or -1 if none is present.

Returns:
this entry's file size

getLastmod

public final long getLastmod()
Returns the last modification date in this directory listing entry, in seconds since the unix epoch. Note that this method will return -1 if no last modification date was sent.

Returns:
this entry's last modification date

getFlags

public final long getFlags()
Returns a the set of flags in this directory listing entry. This will normally be either FLAG_DIR or 0. Note that this value will never be -1; if no flags are sent, this value will simply be 0.

Returns:
this entry's set of bit flags

getTotalTlvCount

public final int getTotalTlvCount()
Returns the total number of TLV's read in constructing this entry object. Note that this value will be -1 if this object was not read from an incoming block of TLV's (with readEntry(net.kano.joscar.tlv.Tlv[], int)).

Returns:
the total number of TLV's read in constructing this entry object

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Description copied from interface: LiveWritable
Writes a representation of this object to the given stream.

Specified by:
write in interface LiveWritable
Parameters:
out - the stream to which to write
Throws:
java.io.IOException - if an I/O error occurs

toString

public java.lang.String toString()