hu.netmind.ogg
Class Page

java.lang.Object
  extended by hu.netmind.ogg.Page
All Implemented Interfaces:
java.io.Serializable

public class Page
extends java.lang.Object
implements java.io.Serializable

This class represents a page in the ogg format, and gives low-level manipulator access to all fields. Constitency checks are also implemented to help building a good ogg page.

See Also:
Serialized Form

Field Summary
static FastCrc fastCrc
           
static byte[] OGG_CAPTURE_PATTERN
           
 
Method Summary
 Packet add(Packet packet)
          Add a packet to this page.
 boolean checkCapturePattern()
          Check capture pattern for ogg.
 boolean checkCrcChecksum()
          Check the crc number in this page.
 long computeCrcChecksum()
          Compute crc number for this page.
static Page fromByteArray(byte[] b)
          Create page from a byte array.
static Page fromByteStream(java.io.InputStream stream)
          Convert a serialized page from a byte stream to a page object.
 int getBitstreamSerialNumber()
           
 byte[] getCapturePattern()
           
 int getCrcChecksum()
           
 long getGranulePosition()
           
 byte getHeaderType()
           
 int getPacketCount()
           
 java.util.Collection getPackets()
          Get all packets in this page.
 int getPageSegments()
           
 int getPageSequenceNumber()
           
 byte getVersion()
           
 boolean isBos()
          Return whether this a begin of stream page.
 boolean isContinued()
          Return whether this page's data belong to the previous packet (that packet is continued in this page).
 boolean isEos()
          Return whether this an end of stream page.
 boolean isFull()
          Returns whether this page is full, or not.
Note:Page is also considered full, if it is a bos page, and one packet is inserted.
 void setBitstreamSerialNumber(int bitstreamSerialNumber)
           
 void setBos()
          Set the bos flag.
 void setCapturePattern(byte[] capturePattern)
           
 void setContinued()
          Set the continued flag.
 void setCrcChecksum(int crcChecksum)
           
 void setEos()
          Set the eos flag.
 void setGranulePosition(long granulePosition)
           
 void setHeaderType(byte headerType)
           
 void setPageSequenceNumber(int pageSequenceNumber)
           
 void setVersion(byte version)
           
 int size()
          The size of data residing in this page.
 byte[] toByteArray()
          Convert this page into a byte array.
 java.lang.String toString()
          Write human readable representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OGG_CAPTURE_PATTERN

public static final byte[] OGG_CAPTURE_PATTERN

fastCrc

public static FastCrc fastCrc
Method Detail

checkCapturePattern

public boolean checkCapturePattern()
Check capture pattern for ogg.

Returns:
True, if this is an ogg capture pattern, false otherwise.

getCapturePattern

public byte[] getCapturePattern()

setCapturePattern

public void setCapturePattern(byte[] capturePattern)

getVersion

public byte getVersion()

setVersion

public void setVersion(byte version)

isBos

public boolean isBos()
Return whether this a begin of stream page.

Returns:
True, if this page is a bos.

isEos

public boolean isEos()
Return whether this an end of stream page.

Returns:
True, if this page is an eos.

setBos

public void setBos()
Set the bos flag.


setEos

public void setEos()
Set the eos flag.


setContinued

public void setContinued()
Set the continued flag.


isContinued

public boolean isContinued()
Return whether this page's data belong to the previous packet (that packet is continued in this page).

Returns:
True, if this data belongs to the previous packet, false if this is a new packet.

getHeaderType

public byte getHeaderType()

setHeaderType

public void setHeaderType(byte headerType)

getGranulePosition

public long getGranulePosition()

setGranulePosition

public void setGranulePosition(long granulePosition)

getBitstreamSerialNumber

public int getBitstreamSerialNumber()

setBitstreamSerialNumber

public void setBitstreamSerialNumber(int bitstreamSerialNumber)

getPageSequenceNumber

public int getPageSequenceNumber()

setPageSequenceNumber

public void setPageSequenceNumber(int pageSequenceNumber)

computeCrcChecksum

public long computeCrcChecksum()
                        throws java.io.IOException
Compute crc number for this page. Note, that crc is generated for the whole page, so all data subsequently modifed will result in a bad crc code.

Returns:
The crc value, which is also set.
Throws:
java.io.IOException - If an error occurs buring converting to byte.

checkCrcChecksum

public boolean checkCrcChecksum()
                         throws java.io.IOException
Check the crc number in this page.

Returns:
True, if crc matches the content of page, false otherwise.
Throws:
java.io.IOException - If an error occurs buring converting to byte.

getCrcChecksum

public int getCrcChecksum()

setCrcChecksum

public void setCrcChecksum(int crcChecksum)

size

public int size()
The size of data residing in this page.


getPageSegments

public int getPageSegments()

isFull

public boolean isFull()
Returns whether this page is full, or not.
Note:Page is also considered full, if it is a bos page, and one packet is inserted. (Per specification the bos page can only contain a single packet)

Returns:
True, if the page is full, no more data will be inserted, and subsequent calls to add() will only return the packet.

getPackets

public java.util.Collection getPackets()
Get all packets in this page. Note, that the first packet may be a part of the packet in the previous page.


getPacketCount

public int getPacketCount()

add

public Packet add(Packet packet)
Add a packet to this page.

Returns:
A packet chunk. If the packet did not fit into this page, this packet chunk is returned. If the page is full, the original packet is returned. If the full packet is inserted, null is returned.
Note that this method only adds the packet, and maintains the segment counter, it does not manipulate any other data, such as the crc, or type indicator bits.

toByteArray

public byte[] toByteArray()
                   throws java.io.IOException
Convert this page into a byte array.

Returns:
The byte array representing this page.
Throws:
java.io.IOException - If the byte array could not be assembled.

fromByteArray

public static Page fromByteArray(byte[] b)
                          throws java.io.IOException
Create page from a byte array.

Parameters:
b - The byte array representing the page.
Throws:
java.io.IOException - If the byte array operations fail.

fromByteStream

public static Page fromByteStream(java.io.InputStream stream)
                           throws java.io.IOException
Convert a serialized page from a byte stream to a page object. This method searches for the next occurence of 'OggS' in the stream, then reads that as a page. The page may still be inconsitent, call checkCrcChecksum() to verify page integrity.

Parameters:
stream - The stream to read.
Returns:
The page object, or null, if stream contained no valid pages.
Throws:
java.io.IOException - If an I/O error occured.

toString

public java.lang.String toString()
Write human readable representation.

Overrides:
toString in class java.lang.Object