edu.harvard.hul.ois.jhove.module.jpeg2000
Class JP2Box

java.lang.Object
  extended by edu.harvard.hul.ois.jhove.module.jpeg2000.BoxHolder
      extended by edu.harvard.hul.ois.jhove.module.jpeg2000.JP2Box
All Implemented Interfaces:
java.util.Iterator<java.lang.Object>
Direct Known Subclasses:
AssociationBox, BinaryFilterBox, BPCCBox, CaptureResolutionBox, ChannelDefBox, CodestreamHeaderBox, CodestreamRegBox, ColorGroupBox, ColorSpecBox, ComponentMapBox, CompOptionsBox, CompositionBox, ComposLayerHdrBox, ContCodestreamBox, CrossRefBox, DataEntryURLBox, DDResolutionBox, DefaultBox, DesiredReproBox, DigSignatureBox, FileTypeBox, FragmentListBox, FragmentTableBox, GTSOBox, ImageHeaderBox, InstructionSetBox, IPRBox, JP2HeaderBox, LabelBox, NumberListBox, OpacityBox, PaletteBox, ReaderRequirementsBox, ResolutionBox, ROIBox, UUIDBox, UUIDInfoBox, UUIDListBox, XMLBox

public abstract class JP2Box
extends BoxHolder

Superclass for JPEG 2000 boxes.

Author:
Gary McGath

Field Summary
protected  long _bytesRead
           
protected  java.util.List<Property> associations
           
protected static java.lang.String DESCRIPTION_NAME
           
protected static java.lang.String noJP2Hdr
           
protected  long startBytesRead
           
 
Fields inherited from class edu.harvard.hul.ois.jhove.module.jpeg2000.BoxHolder
_boxHeader, _dstrm, _module, _parentBox, _raf, _repInfo, bytesLeft, filePos, hasBoxes
 
Constructor Summary
JP2Box(java.io.RandomAccessFile raf)
          Constructor.
JP2Box(java.io.RandomAccessFile raf, BoxHolder parent)
          Constructor for a box which is found within a superbox.
 
Method Summary
protected  void addAssociation(Property p)
           
static JP2Box boxMaker(java.lang.String hType, BoxHolder parent)
          Static factory method for generating an object of the appropriate subclass of MarkerSegment, based on the box type.
protected  void emptyBox()
          Utility error reporting function for a box which is expected to have subboxes, but doesn't.
protected  void finalizeBytesRead()
           
 int getBytesRead()
           
protected  long getLength()
          Returns the length of the box, including header, based on the information in the header.
protected  Property getSelfPropDesc()
          Returns a Property which describes the box.
protected  java.lang.String getSelfPropName()
          Returns the name of the Box.
protected  void init(BoxHolder parent)
           
protected  void initBytesRead()
           
protected  Property makeAssocProperty()
          Make a Property from the association list.
abstract  boolean readBox()
          Reads the box, putting appropriate information in the RepInfo object.
protected  Property selfDescProperty()
          Returns a Property which describes the Box, for use by Association boxes and perhaps others.
 void setBoxHeader(BoxHeader hdr)
          Sets the BoxHeader from which this Box was obtained.
 void setDataInputStream(java.io.DataInputStream dstrm)
          Assigns the DataInputStream from which the box is being read.
 void setModule(Jpeg2000Module module)
          Sets the module under which the Box is being read.
 void setRandomAccessFile(java.io.RandomAccessFile raf)
          Assigns the RandomAccessFile from which the box is being read.
 void setRepInfo(RepInfo info)
          Assigns a RepInfo object, so that subclasses of JP2Box can add Properties and Messages.
 void skipBox()
          Skips over the box.
protected  void wrongBoxContext()
          Utility error reporting function for box in a context (superbox or lack thereof) which is not permitted.
protected  void wrongBoxSize()
          Utility error reporting function for incorrect box length.
 
Methods inherited from class edu.harvard.hul.ois.jhove.module.jpeg2000.BoxHolder
getFilePos, hasNext, next, remove, superboxOverrun, superboxUnderrun
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startBytesRead

protected long startBytesRead

_bytesRead

protected long _bytesRead

associations

protected java.util.List<Property> associations

noJP2Hdr

protected static final java.lang.String noJP2Hdr
See Also:
Constant Field Values

DESCRIPTION_NAME

protected static final java.lang.String DESCRIPTION_NAME
See Also:
Constant Field Values
Constructor Detail

JP2Box

public JP2Box(java.io.RandomAccessFile raf)
Constructor. Has no arguments, so that invoking lots of different subclasses is relatively simple. setModule, setBoxHeader, setRepInfo, and setDataInputStream should be called immediately after the constructor.


JP2Box

public JP2Box(java.io.RandomAccessFile raf,
              BoxHolder parent)
Constructor for a box which is found within a superbox.

Parameters:
parent - parent superbox of this box
Method Detail

init

protected void init(BoxHolder parent)

setModule

public void setModule(Jpeg2000Module module)
Sets the module under which the Box is being read.


setBoxHeader

public void setBoxHeader(BoxHeader hdr)
Sets the BoxHeader from which this Box was obtained.


setRepInfo

public void setRepInfo(RepInfo info)
Assigns a RepInfo object, so that subclasses of JP2Box can add Properties and Messages.


setDataInputStream

public void setDataInputStream(java.io.DataInputStream dstrm)
Assigns the DataInputStream from which the box is being read.


setRandomAccessFile

public void setRandomAccessFile(java.io.RandomAccessFile raf)
Assigns the RandomAccessFile from which the box is being read.


boxMaker

public static JP2Box boxMaker(java.lang.String hType,
                              BoxHolder parent)
Static factory method for generating an object of the appropriate subclass of MarkerSegment, based on the box type. This is for use in top-level reading of boxes, not subboxes. Provision is made for calling this with a parent box, but the set of boxes dispatched on is the set used at top level. Certain box types have magical characteristics and have to be checked by the BoxHolder. These include BinaryFilterBox and CrossReferenceBox.

Parameters:
hType - 4-character string indicating the box type
parent - parent BoxHolder

initBytesRead

protected void initBytesRead()

finalizeBytesRead

protected void finalizeBytesRead()

readBox

public abstract boolean readBox()
                         throws java.io.IOException
Reads the box, putting appropriate information in the RepInfo object. setModule, setBoxHeader, setRepInfo and setDataInputStream must be called before readBox is called. Thus, the header of the box must already have been read. readBox must completely consume the box, so that the next byte to be read by the DataInputStream is the FF byte of the next Box. The number of bytes read must be placed in _bytesRead.

Throws:
java.io.IOException

getBytesRead

public int getBytesRead()

skipBox

public void skipBox()
             throws java.io.IOException
Skips over the box. Can be called when the box is legal but meaningless in the current context.

Throws:
java.io.IOException

addAssociation

protected void addAssociation(Property p)

wrongBoxSize

protected void wrongBoxSize()
Utility error reporting function for incorrect box length. Sets the RepInfo's wellFormed flag to false.


wrongBoxContext

protected void wrongBoxContext()
Utility error reporting function for box in a context (superbox or lack thereof) which is not permitted. Sets the RepInfo's wellFormed flag to false.


emptyBox

protected void emptyBox()
Utility error reporting function for a box which is expected to have subboxes, but doesn't.


makeAssocProperty

protected Property makeAssocProperty()
Make a Property from the association list. Returns null if the list is empty.


selfDescProperty

protected Property selfDescProperty()
Returns a Property which describes the Box, for use by Association boxes and perhaps others. Most subclasses will only have to override getSelfPropName and getSelfPropDesc. A subclass that shouldn't be added to the Association box's property can override this to return null.


getSelfPropName

protected java.lang.String getSelfPropName()
Returns the name of the Box. All Boxes should override this.

Overrides:
getSelfPropName in class BoxHolder

getSelfPropDesc

protected Property getSelfPropDesc()
Returns a Property which describes the box. This is used as a subproperty of the Property returned by selfDescProperty. Properties that we don't care to describe don't have to override this. This class should return either null or a property with DESCRIPTION_NAME for its name.


getLength

protected long getLength()
Returns the length of the box, including header, based on the information in the header.