Package com.bfo.box
Class BoxFactory
java.lang.Object
com.bfo.box.BoxFactory
The BoxFactory creates
Box
objects from an InputStream
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new Boxboolean
isContainer
(String tag) Return true if the specified type is a containerload
(InputStream stream) Read a Box from the InputStream.load
(ByteBuffer data) Read a Box from a ByteBuffer.void
Register a new Box type.void
If no registrations are made when this factory is first used, this method will be called to register several defaults.subFactory
(Box override) Create a version of this factory where the first Box it creates is the supplied one, before falling back to normal behaviour.
-
Constructor Details
-
BoxFactory
public BoxFactory()Create a new BoxFactory
-
-
Method Details
-
isContainer
Return true if the specified type is a container- Parameters:
tag
- the tag- Returns:
- whether box with that tag is a container
- See Also:
-
createBox
Create a new Box- Parameters:
type
- the typesubtype
- the subtype (if type requires subtypes), or nulllabel
- if the box type is jumb, the label from the nested decription, or null- Returns:
- a new Box
- See Also:
-
register
public void register(String type, String subtype, String label, boolean container, Class<? extends Box> clazz) Register a new Box type. Calls tocreateBox(java.lang.String, java.lang.String, java.lang.String)
will match the registered types to determine which type to create- Parameters:
type
- the type, a four-letter code, or null to set the default Box type (which defaults toBox
but could beDataBox
to load unrecognised boxes into memorysubtype
- the subtype, if this box type begins with a 16-byte ISO extension (seeExtensionBox
which should be extracted as subtype. May be nulllabel
- the label to match against the nested "jumd" box. May be nullcontainer
- if true boxes of this type will be registered as containers, and will create children when readclazz
- the subclass of Box to create
-
load
Read a Box from a ByteBuffer.- Parameters:
data
- the byte buffer to load from- Returns:
- the box, or
null
if the stream is fully consumed - Throws:
IOException
- if the stream is corrupt or fails to read
-
load
Read a Box from the InputStream.- Parameters:
stream
- the InputStream.- Returns:
- the box, or
null
if the stream is fully consumed - Throws:
IOException
- if the stream is corrupt or fails to read
-
subFactory
Create a version of this factory where the first Box it creates is the supplied one, before falling back to normal behaviour. Used to force typing fromBox.read(java.io.InputStream, com.bfo.box.BoxFactory)
- Parameters:
override
- the overridden box type- Returns:
- the sub-factory
-
registerDefaults
public void registerDefaults()If no registrations are made when this factory is first used, this method will be called to register several defaults. Should be called from the constructor for subclasses of this factory
-