Class Box
- java.lang.Object
-
- com.github.jaiimageio.jpeg2000.impl.Box
-
- Direct Known Subclasses:
BitsPerComponentBox,ChannelDefinitionBox,ColorSpecificationBox,ComponentMappingBox,DataEntryURLBox,FileTypeBox,HeaderBox,PaletteBox,ResolutionBox,SignatureBox,UUIDBox,UUIDListBox,XMLBox
public class Box extends Object
This class is defined to create the box of JP2 file format. A box has a length, a type, an optional extra length and its content. The subclasses should explain the content information.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]dataprotected longextraLengthprotected intlengthBox length, extra length, type and content data arrayprotected inttype
-
Constructor Summary
Constructors Constructor Description Box(int length, int type, byte[] data)Constructs aBoxinstance using the provided the box type and the box content in byte array format.Box(int length, int type, long extraLength, byte[] data)Constructs aBoxinstance using the provided the box type, the box extra length, and the box content in byte array format.Box(ImageInputStream iis, int pos)Constructs aBoxinstance from the providedImageInputStreamat the specified position.Box(Node node)Constructs a Box from an "unknown" Node.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcompose()Composes the content byte array from the data elements.static voidcopyInt(byte[] data, int pos, int value)Copies that four bytes of an integer into the byte array.static BoxcreateBox(int type, Node node)Creates aBoxobject with the providedtypebased on the provided Node object based on reflection.static ObjectgetAttribute(Node node, String name)Extracts the value of the attribute from name.static ClassgetBoxClass(int type)Returns the Box class for the box with the providedtype.protected static byte[]getByteArrayElementValue(Node node)Gets the byte array from anIIOMetadataNode.protected static bytegetByteElementValue(Node node)Gets its byte value from anIIOMetadataNode.byte[]getContent()Returns the box content in byte array.longgetExtraLength()Returns the box extra length.protected static int[]getIntArrayElementValue(Node node)Gets the integer array from anIIOMetadataNode.protected static intgetIntElementValue(Node node)Gets its integer value from anIIOMetadataNode.intgetLength()Returns the box length.static StringgetName(int type)Returns the XML tag name defined in JP2 XML xsd/dtd for the box with the providedtype.IIOMetadataNodegetNativeNode()Creates anIIOMetadataNodefrom this box.protected IIOMetadataNodegetNativeNodeForSimpleBox()Creates anIIOMetadataNodefrom this box.protected static shortgetShortElementValue(Node node)Gets its short value from anIIOMetadataNode.protected static StringgetStringElementValue(Node node)Gets itsStringvalue from anIIOMetadataNode.intgetType()Returns the box type.static StringgetTypeByName(String name)Returns the type String based on the provided name.static intgetTypeInt(String s)Converts the box type from integer to string.static StringgetTypeString(int type)Converts the box type from integer to string.protected voidparse(byte[] data)Parses the data elements from the byte array.static byte[]parseByteArray(String value)Parses the byte array expressed by a string.protected static int[]parseIntArray(String value)Parses the integer array expressed a string.voidread(ImageInputStream iis, int pos)Reads a box from theImageInputStreamvoidsetContent(byte[] data)Sets the box content.protected voidsetDefaultAttributes(IIOMetadataNode node)Sets the default attributes, "Length", "Type", and "ExtraLength", to the providedIIOMetadataNode.voidsetExtraLength(long extraLength)Sets the box extra length length to the provided value.voidsetLength(int length)Sets the box length to the provided value.voidwrite(ImageOutputStream ios)Writes this box instance into aImageOutputStream.
-
-
-
Field Detail
-
length
protected int length
Box length, extra length, type and content data array
-
extraLength
protected long extraLength
-
type
protected int type
-
data
protected byte[] data
-
-
Constructor Detail
-
Box
public Box(int length, int type, byte[] data)
Constructs aBoxinstance using the provided the box type and the box content in byte array format.- Parameters:
length- The provided box length.type- The provided box type.data- The provided box content in a byte array.- Throws:
IllegalArgumentException- If the length of the content byte array is not length - 8.
-
Box
public Box(int length, int type, long extraLength, byte[] data)
Constructs aBoxinstance using the provided the box type, the box extra length, and the box content in byte array format. In this case, the length of the box is set to 1, which indicates the extra length is meaningful.- Parameters:
length- The provided box length.type- The provided box type.extraLength- The provided box extra length.data- The provided box content in a byte array.- Throws:
IllegalArgumentException- If the length of the content byte array is not extra length - 16.
-
Box
public Box(ImageInputStream iis, int pos) throws IOException
Constructs aBoxinstance from the providedImageInputStreamat the specified position.- Parameters:
iis- TheImageInputStreamcontains the box.pos- The position from where to read the box.- Throws:
IOException- If any IOException is thrown in the called read methods.
-
Box
public Box(Node node) throws IIOInvalidTreeException
Constructs a Box from an "unknown" Node. This node has at least the attribute "Type", and may have the attribute "Length", "ExtraLength" and a child "Content". The child node content is a IIOMetaDataNode with a byte[] user object.- Throws:
IIOInvalidTreeException
-
-
Method Detail
-
getName
public static String getName(int type)
Returns the XML tag name defined in JP2 XML xsd/dtd for the box with the providedtype. If thetypeis not known, the string"unknown"is returned.
-
getBoxClass
public static Class getBoxClass(int type)
Returns the Box class for the box with the providedtype.
-
getTypeByName
public static String getTypeByName(String name)
Returns the type String based on the provided name.
-
createBox
public static Box createBox(int type, Node node) throws IIOInvalidTreeException
Creates aBoxobject with the providedtypebased on the provided Node object based on reflection.- Throws:
IIOInvalidTreeException
-
getAttribute
public static Object getAttribute(Node node, String name)
Extracts the value of the attribute from name.
-
parseByteArray
public static byte[] parseByteArray(String value)
Parses the byte array expressed by a string.
-
parseIntArray
protected static int[] parseIntArray(String value)
Parses the integer array expressed a string.
-
getStringElementValue
protected static String getStringElementValue(Node node)
Gets itsStringvalue from anIIOMetadataNode.
-
getByteElementValue
protected static byte getByteElementValue(Node node)
Gets its byte value from anIIOMetadataNode.
-
getIntElementValue
protected static int getIntElementValue(Node node)
Gets its integer value from anIIOMetadataNode.
-
getShortElementValue
protected static short getShortElementValue(Node node)
Gets its short value from anIIOMetadataNode.
-
getByteArrayElementValue
protected static byte[] getByteArrayElementValue(Node node)
Gets the byte array from anIIOMetadataNode.
-
getIntArrayElementValue
protected static int[] getIntArrayElementValue(Node node)
Gets the integer array from anIIOMetadataNode.
-
copyInt
public static void copyInt(byte[] data, int pos, int value)
Copies that four bytes of an integer into the byte array. Necessary for the subclasses to compose the content array from the data elements
-
getTypeString
public static String getTypeString(int type)
Converts the box type from integer to string. This is necessary because type is defined as String in xsd/dtd and integer in the box classes.
-
getTypeInt
public static int getTypeInt(String s)
Converts the box type from integer to string. This is necessary because type is defined as String in xsd/dtd and integer in the box classes.
-
getNativeNode
public IIOMetadataNode getNativeNode()
Creates anIIOMetadataNodefrom this box. The format of this node is defined in the XML dtd and xsd for the JP2 image file.
-
getNativeNodeForSimpleBox
protected IIOMetadataNode getNativeNodeForSimpleBox()
Creates anIIOMetadataNodefrom this box. The format of this node is defined in the XML dtd and xsd for the JP2 image file. This method is designed for the types of boxes whose XML tree only has 2 levels.
-
setDefaultAttributes
protected void setDefaultAttributes(IIOMetadataNode node)
Sets the default attributes, "Length", "Type", and "ExtraLength", to the providedIIOMetadataNode.
-
getLength
public int getLength()
Returns the box length.
-
getType
public int getType()
Returns the box type.
-
getExtraLength
public long getExtraLength()
Returns the box extra length.
-
getContent
public byte[] getContent()
Returns the box content in byte array.
-
setLength
public void setLength(int length)
Sets the box length to the provided value.
-
setExtraLength
public void setExtraLength(long extraLength)
Sets the box extra length length to the provided value.
-
setContent
public void setContent(byte[] data)
Sets the box content. If the content length is not length -8 or extra length - 16, IllegalArgumentException will be thrown.
-
write
public void write(ImageOutputStream ios) throws IOException
Writes this box instance into aImageOutputStream.- Throws:
IOException
-
read
public void read(ImageInputStream iis, int pos) throws IOException
Reads a box from theImageInputStream- Throws:
IOException
-
parse
protected void parse(byte[] data)
Parses the data elements from the byte array. The subclasses should override this method.
-
compose
protected void compose()
Composes the content byte array from the data elements.
-
-