Package com.bfo.box

Class BoxFactory

java.lang.Object
com.bfo.box.BoxFactory

public class BoxFactory extends Object
The BoxFactory creates Box objects from an InputStream.
  • Constructor Details

    • BoxFactory

      public BoxFactory()
      Create a new BoxFactory
  • Method Details

    • isContainer

      public boolean isContainer(String tag)
      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

      public Box createBox(String type, String subtype, String label)
      Create a new Box
      Parameters:
      type - the type
      subtype - the subtype (if type requires subtypes), or null
      label - 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 to createBox(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 to Box but could be DataBox to load unrecognised boxes into memory
      subtype - the subtype, if this box type begins with a 16-byte ISO extension (see ExtensionBox which should be extracted as subtype. May be null
      label - the label to match against the nested "jumd" box. May be null
      container - if true boxes of this type will be registered as containers, and will create children when read
      clazz - the subclass of Box to create
    • load

      public Box load(ByteBuffer data) throws IOException
      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

      public Box load(InputStream stream) throws IOException
      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

      public BoxFactory 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. Used to force typing from Box.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