com.zipxap.vfs
Class VFSSector

java.lang.Object
  extended by com.zipxap.vfs.VFSSector

public class VFSSector
extends java.lang.Object

A Sector is X bytes of contiguous data, where X is one of six sizes; Header, Small, Medium, Large, Jumbo, Giant.

Headers

Header sectors are extremely small and begin with byte 'H' (or 'h' if empty). The next 3 bytes are a spacer to make the other sector sizes divisible by the header sector size, The next 4 bytes are the (int) size of the entry sector, followed by 8 bytes that contain the (long) location of the entry sector. The next 8 bytes are the (long) size of the data sector. Like all sectors, the last 8 bytes contain the (long) address of the sector contain the location of the next sector in the series, or -1 if this is the last sector in the series.

Non Headers

The last 8 bytes contain the (long) address of the sector contain the location of the next sector in the series, or -1 if this is the last sector in the series.

This means, for a given sector size X, there are X-9 bytes available to store data.

MilestoneWhoDate, Time
Initial VersionK PenroseJune 2009

** Note that this table is not intended as an exhaustive list of subtle changes. It is intended to list changes that break the compatibility of older code, or major enhancements/rewrites


Field Summary
 long _dataIndex
           
static long DATA_START_OFFSET
           
static int HEADER_DATA_SIZE_OFFSET
           
static int HEADER_ENTRY_LOCATION_OFFSET
           
static int HEADER_ENTRY_SIZE_OFFSET
           
 
Constructor Summary
VFSSector(LowLevelManager mgr, long fileLocation)
          Create a new sector object to represent an existing sector
VFSSector(LowLevelManager mgr, long fileLocation, SectorType sectorType)
          Create a new sector object to represent an existing sector
 
Method Summary
static VFSSector appendNewEmptySectors(LowLevelManager mgr, SectorType type)
          Create a new empty sector and append it to the end of the archive.
 void convertToEmpty(boolean convertRemainingLinkedSectors)
          Converts this sector to an empty sector and, optionally, any remaining linked sectors.
 void dumpLinkedSectors()
          Converts the remaining linked sectors to empty sectors
 long getDataLength()
          Retrieves the length (in bytes) of the data.
 ValuePair<java.lang.Long,VFSSector> getDataSector()
          Retrieves the data sector from a header sector.
 Entry getEntry()
          Retrieve the Entry contained in this sector
 int getEntryLength()
          Retrieves the length (in bytes) of the entry.
 ValuePair<java.lang.Integer,VFSSector> getEntrySector()
           
 ValuePair<java.lang.Integer,VFSSector> getEntrySector(boolean createIfItDoesntExist)
          Retrieves the entry sector (if this is a header sector).
 java.lang.Long getEntrySectorLocation()
          Retrieves the location of the entry sector, if it has one.
 long getFileLocation()
           
 VFSSector getNextSector()
          Retrieves the next sector in the series.
 java.lang.Long getNextSectorLocation()
          Retrieves the next sector in the series (which is also the dataSector if this is a header).
 int getNextSectorOffset()
           
 int getRemainingDataLengthBytes()
          Determine if there is more data in this sector to be read.
 int getSectorSize()
           
 SectorType getSectorType()
           
 void initPointer()
          Initialize the sector to read the data, starting at the first data location within the sector.
 boolean isEmpty()
           
 VFSSector linkNewSector(SectorType sectorType)
          Returns the currently linked sector if there is one, else it creates a new one.
 VFSSector morphThisSectorToNextSector()
          This is a helper method that is functionally similar to reindexSector(getNextSector().getFileLocation()) (but safe).
 int read()
           
 int readNotBuffered()
           
 void reindexSector(long newFileLocation)
          Reindex this sector using the specified location as the file location of this sector.
 void setDataLength(long length)
           
 void setEntryLength(long length)
           
 void setEntrySectorLocation(java.lang.Long entrySectorLocation)
          Set the location of the entry sector.
 void setNextSectorLocation(java.lang.Long nextSectorLocation)
          Sets the location of the next sector in the series (which is also the dataSector if this is a header).
 void setSectorType(SectorType sectorType)
           
 int writeData(byte[] data, int offset, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_START_OFFSET

public static final long DATA_START_OFFSET
See Also:
Constant Field Values

HEADER_ENTRY_SIZE_OFFSET

public static final int HEADER_ENTRY_SIZE_OFFSET
See Also:
Constant Field Values

HEADER_ENTRY_LOCATION_OFFSET

public static final int HEADER_ENTRY_LOCATION_OFFSET
See Also:
Constant Field Values

HEADER_DATA_SIZE_OFFSET

public static final int HEADER_DATA_SIZE_OFFSET
See Also:
Constant Field Values

_dataIndex

public long _dataIndex
Constructor Detail

VFSSector

public VFSSector(LowLevelManager mgr,
                 long fileLocation)
Create a new sector object to represent an existing sector

Parameters:
mgr -
fileLocation -

VFSSector

public VFSSector(LowLevelManager mgr,
                 long fileLocation,
                 SectorType sectorType)
Create a new sector object to represent an existing sector

Parameters:
mgr -
fileLocation -
Method Detail

appendNewEmptySectors

public static VFSSector appendNewEmptySectors(LowLevelManager mgr,
                                              SectorType type)
Create a new empty sector and append it to the end of the archive.

Parameters:
mgr -
Returns:
the newly created empty sector.

getSectorType

public SectorType getSectorType()

setSectorType

public void setSectorType(SectorType sectorType)

getNextSector

public VFSSector getNextSector()
Retrieves the next sector in the series.

Returns:
The next sector in the series, or null if there isn't one

getNextSectorLocation

public java.lang.Long getNextSectorLocation()
Retrieves the next sector in the series (which is also the dataSector if this is a header).

Returns:
The next sector in the series, or null if there isn't one

setNextSectorLocation

public void setNextSectorLocation(java.lang.Long nextSectorLocation)
Sets the location of the next sector in the series (which is also the dataSector if this is a header).


getDataSector

public ValuePair<java.lang.Long,VFSSector> getDataSector()
Retrieves the data sector from a header sector.

Returns:
The next sector in the series, or null if there isn't one

getDataLength

public long getDataLength()
Retrieves the length (in bytes) of the data.


setDataLength

public void setDataLength(long length)

getEntryLength

public int getEntryLength()
Retrieves the length (in bytes) of the entry.


setEntryLength

public void setEntryLength(long length)

getEntrySector

public ValuePair<java.lang.Integer,VFSSector> getEntrySector()

getEntrySectorLocation

public java.lang.Long getEntrySectorLocation()
Retrieves the location of the entry sector, if it has one.

Returns:
The size and next sector in the series, or null if there isn't one

setEntrySectorLocation

public void setEntrySectorLocation(java.lang.Long entrySectorLocation)
Set the location of the entry sector. An exception will be thrown if this sector is not a header sector.


getEntrySector

public ValuePair<java.lang.Integer,VFSSector> getEntrySector(boolean createIfItDoesntExist)
Retrieves the entry sector (if this is a header sector).

Returns:
The size and next sector in the series, or null if there isn't one

reindexSector

public void reindexSector(long newFileLocation)
Reindex this sector using the specified location as the file location of this sector.

Parameters:
newFileLocation -

morphThisSectorToNextSector

public VFSSector morphThisSectorToNextSector()
This is a helper method that is functionally similar to reindexSector(getNextSector().getFileLocation()) (but safe).

Returns:
a self reference, morphed into the next sector if their is one, else null if there is no next sector.

linkNewSector

public VFSSector linkNewSector(SectorType sectorType)
Returns the currently linked sector if there is one, else it creates a new one.

Returns:
the currently or newly linked sector

convertToEmpty

public void convertToEmpty(boolean convertRemainingLinkedSectors)
Converts this sector to an empty sector and, optionally, any remaining linked sectors.


dumpLinkedSectors

public void dumpLinkedSectors()
Converts the remaining linked sectors to empty sectors


initPointer

public void initPointer()
Initialize the sector to read the data, starting at the first data location within the sector.


read

public int read()
Returns:
the next byte of data from the sector

readNotBuffered

public int readNotBuffered()

getRemainingDataLengthBytes

public int getRemainingDataLengthBytes()
Determine if there is more data in this sector to be read.

Returns:
the number of bytes remaining in this sector for read/write

getFileLocation

public long getFileLocation()

getSectorSize

public int getSectorSize()

isEmpty

public boolean isEmpty()

getNextSectorOffset

public int getNextSectorOffset()

writeData

public int writeData(byte[] data,
                     int offset,
                     int length)

getEntry

public Entry getEntry()
Retrieve the Entry contained in this sector

Returns:
the Entry contained in this sector, or null if there isn't one.