public class Box extends Object
Modifier and Type | Field and Description |
---|---|
private static Hashtable |
boxClasses
A Hashtable contains the class names for each type of the boxes.
|
protected byte[] |
data |
protected long |
extraLength |
protected int |
length
Box length, extra length, type and content data array
|
private static Hashtable |
names
The table to link tag names for all the JP2 boxes.
|
protected int |
type |
Constructor and Description |
---|
Box(ImageInputStream iis,
int pos)
Constructs a
Box instance from the provided
ImageInputStream at the specified position. |
Box(int length,
int type,
byte[] data)
Constructs a
Box instance using the provided
the box type and the box content in byte array format. |
Box(int length,
int type,
long extraLength,
byte[] data)
Constructs a
Box instance using the provided
the box type, the box extra length, and the box content in byte
array format. |
Box(Node node)
Constructs a Box from an "unknown" Node.
|
Modifier and Type | Method and Description |
---|---|
protected void |
compose()
Composes the content byte array from the data elements.
|
static void |
copyInt(byte[] data,
int pos,
int value)
Copies that four bytes of an integer into the byte array.
|
static Box |
createBox(int type,
Node node)
Creates a
Box object with the provided type
based on the provided Node object based on reflection. |
static Object |
getAttribute(Node node,
String name)
Extracts the value of the attribute from name.
|
static Class |
getBoxClass(int type)
Returns the Box class for the box with the provided
type . |
protected static byte[] |
getByteArrayElementValue(Node node)
Gets the byte array from an
IIOMetadataNode . |
protected static byte |
getByteElementValue(Node node)
Gets its byte value from an
IIOMetadataNode . |
byte[] |
getContent()
Returns the box content in byte array.
|
long |
getExtraLength()
Returns the box extra length.
|
protected static int[] |
getIntArrayElementValue(Node node)
Gets the integer array from an
IIOMetadataNode . |
protected static int |
getIntElementValue(Node node)
Gets its integer value from an
IIOMetadataNode . |
int |
getLength()
Returns the box length.
|
static String |
getName(int type)
Returns the XML tag name defined in JP2 XML xsd/dtd for the box
with the provided
type . |
IIOMetadataNode |
getNativeNode()
Creates an
IIOMetadataNode from this
box. |
protected IIOMetadataNode |
getNativeNodeForSimpleBox()
Creates an
IIOMetadataNode from this
box. |
protected static short |
getShortElementValue(Node node)
Gets its short value from an
IIOMetadataNode . |
protected static String |
getStringElementValue(Node node)
Gets its
String value from an IIOMetadataNode . |
int |
getType()
Returns the box type.
|
static String |
getTypeByName(String name)
Returns the type String based on the provided name.
|
static int |
getTypeInt(String s)
Converts the box type from integer to string.
|
static String |
getTypeString(int type)
Converts the box type from integer to string.
|
protected void |
parse(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.
|
void |
read(ImageInputStream iis,
int pos)
Reads a box from the ImageInputStream
|
void |
setContent(byte[] data)
Sets the box content.
|
protected void |
setDefaultAttributes(IIOMetadataNode node)
Sets the default attributes, "Length", "Type", and "ExtraLength", to
the provided
IIOMetadataNode . |
void |
setExtraLength(long extraLength)
Sets the box extra length length to the provided value.
|
void |
setLength(int length)
Sets the box length to the provided value.
|
void |
write(ImageOutputStream ios)
Writes this box instance into a
ImageOutputStream . |
private static Hashtable names
private static Hashtable boxClasses
protected int length
protected long extraLength
protected int type
protected byte[] data
public Box(int length, int type, byte[] data)
Box
instance using the provided
the box type and the box content in byte array format.length
- The provided box length.type
- The provided box type.data
- The provided box content in a byte array.IllegalArgumentException
- If the length of the content byte array
is not length - 8.public Box(int length, int type, long extraLength, byte[] data)
Box
instance 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.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.IllegalArgumentException
- If the length of the content byte array
is not extra length - 16.public Box(ImageInputStream iis, int pos) throws IOException
Box
instance from the provided
ImageInputStream
at the specified position.iis
- The ImageInputStream
contains the box.pos
- The position from where to read the box.IOException
- If any IOException is thrown in the called read
methods.public Box(Node node) throws IIOInvalidTreeException
IIOInvalidTreeException
public static String getName(int type)
type
. If the type
is
not known, the string "unknown"
is returned.public static Class getBoxClass(int type)
type
.public static String getTypeByName(String name)
public static Box createBox(int type, Node node) throws IIOInvalidTreeException
Box
object with the provided type
based on the provided Node object based on reflection.IIOInvalidTreeException
public static Object getAttribute(Node node, String name)
public static byte[] parseByteArray(String value)
protected static int[] parseIntArray(String value)
protected static String getStringElementValue(Node node)
String
value from an IIOMetadataNode
.protected static byte getByteElementValue(Node node)
IIOMetadataNode
.protected static int getIntElementValue(Node node)
IIOMetadataNode
.protected static short getShortElementValue(Node node)
IIOMetadataNode
.protected static byte[] getByteArrayElementValue(Node node)
IIOMetadataNode
.protected static int[] getIntArrayElementValue(Node node)
IIOMetadataNode
.public static void copyInt(byte[] data, int pos, int value)
public static String getTypeString(int type)
public static int getTypeInt(String s)
public IIOMetadataNode getNativeNode()
IIOMetadataNode
from this
box. The format of this node is defined in the XML dtd and xsd
for the JP2 image file.protected IIOMetadataNode getNativeNodeForSimpleBox()
IIOMetadataNode
from 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.protected void setDefaultAttributes(IIOMetadataNode node)
IIOMetadataNode
.public int getLength()
public int getType()
public long getExtraLength()
public byte[] getContent()
public void setLength(int length)
public void setExtraLength(long extraLength)
public void setContent(byte[] data)
public void write(ImageOutputStream ios) throws IOException
ImageOutputStream
.IOException
public void read(ImageInputStream iis, int pos) throws IOException
ImageInputStream
- 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.
Copyright © 2016 Open Microscopy Environment