Interface BinaryObject

All Known Implementing Classes:
Animated, Animated.Entry, Blockmap, BSPNode, BSPSegment, BSPSubsector, Colormap, CommonPatch, CommonTexture, CommonTextureList, Demo, DMXSound, DoomLinedef, DoomSector, DoomSidedef, DoomTextureList, DoomTextureList.Texture, DoomTextureList.Texture.Patch, DoomThing, DoomVertex, EndDoom, Flat, HexenLinedef, HexenThing, MUS, Palette, PatchNames, Picture, PNGPicture, Reject, StrifeTextureList, StrifeTextureList.Texture, StrifeTextureList.Texture.Patch, Switches, Switches.Entry

public interface BinaryObject
Common elements of all objects that are loaded from binary data. This provides a general interface for getting serialized object data.
Author:
Matthew Tropiano
  • Method Details

    • readBytes

      void readBytes(InputStream in) throws IOException
      Reads from an InputStream and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!
      Parameters:
      in - the InputStream to read from.
      Throws:
      IOException - if a read error occurs.
    • readFile

      default void readFile(File file) throws IOException
      Reads from a File and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!
      Parameters:
      file - the File to read from.
      Throws:
      FileNotFoundException - if the file could not be found.
      IOException - if a read error occurs.
      SecurityException - if the file could not be opened due to OS permissions.
      Since:
      2.13.0
    • writeBytes

      void writeBytes(OutputStream out) throws IOException
      Writes this object to an OutputStream.
      Parameters:
      out - the OutputStream to write to.
      Throws:
      IOException - if a write error occurs.
    • writeFile

      default void writeFile(File file) throws IOException
      Writes this object to a File. The file's contents are overwritten.
      Parameters:
      file - the File to write to.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
      See Also:
    • writeFile

      default void writeFile(File file, boolean append) throws IOException
      Writes this object to a File.
      Parameters:
      file - the File to write to.
      append - if true, the content is written to the end of the file.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
    • toBytes

      default byte[] toBytes()
      Gets the byte representation of this object.
      Returns:
      this object as a series of bytes.
    • fromBytes

      default void fromBytes(byte[] data) throws IOException
      Reads in the byte representation of this object and sets its fields.
      Parameters:
      data - the byte array to read from.
      Throws:
      IOException - if a read error occurs.
    • toBytes

      static <BO extends BinaryObject> byte[] toBytes(BO[] data)
      Converts an array of BinaryObjects into bytes.
      Type Parameters:
      BO - the BinaryObject type.
      Parameters:
      data - the objects to convert.
      Returns:
      the data bytes.
      Since:
      2.4.0
    • create

      static <BO extends BinaryObject> BO create(Class<BO> boClass, byte[] b) throws IOException
      Creates a single object of a specific class from a serialized byte array.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      b - the array of bytes.
      Returns:
      a single instance of the created object.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • read

      static <BO extends BinaryObject> BO read(Class<BO> boClass, InputStream in) throws IOException
      Creates a single object of a specific class from from an InputStream.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      in - the input stream.
      Returns:
      a single instance of the created object.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • read

      static <BO extends BinaryObject> BO read(Class<BO> boClass, File file) throws IOException
      Creates a single object of a specific class from from a File.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      file - the source file.
      Returns:
      a single instance of the created object.
      Throws:
      FileNotFoundException - if the file could not be found.
      IOException - if an error occurs during the read - most commonly "not enough bytes".
      SecurityException - if the file could not be opened due to OS permissions.
      Since:
      2.13.0
    • create

      static <BO extends BinaryObject> BO[] create(Class<BO> boClass, byte[] b, int count) throws IOException
      Creates an amount of objects of a specific class from a serialized byte array.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      b - the array of bytes.
      count - the (maximum) amount of objects to read.
      Returns:
      an array of length count of the created objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • read

      static <BO extends BinaryObject> BO[] read(Class<BO> boClass, InputStream in, int count) throws IOException
      Creates an amount of objects of a specific class from an InputStream.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      in - the input stream.
      count - the (maximum) amount of objects to read.
      Returns:
      an array of length count of the created objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • read

      static <BO extends BinaryObject> BO[] read(Class<BO> boClass, File file, int count) throws IOException
      Creates an amount of objects of a specific class from a File.
      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      file - the source file.
      count - the (maximum) amount of objects to read.
      Returns:
      an array of length count of the created objects.
      Throws:
      FileNotFoundException - if the file could not be found.
      IOException - if an error occurs during the read - most commonly "not enough bytes".
      SecurityException - if the file could not be opened due to OS permissions.
      Since:
      2.13.0
    • scanner

      static <BO extends BinaryObject> BinaryObject.Scanner<BO> scanner(Class<BO> boClass, InputStream in, int length) throws IOException
      Creates a deserializing scanner iterator that returns independent instances of objects.

      NOTE: The InputStream is closed after the last object is read.

      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      in - the input stream.
      length - the length of each object to read.
      Returns:
      a Scanner object for reading the objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • inlineScanner

      static <BO extends BinaryObject> BinaryObject.InlineScanner<BO> inlineScanner(Class<BO> boClass, InputStream in, int length) throws IOException
      Creates a deserializing scanner iterator that returns the same object instance with its contents changed. This is useful for when you would want to quickly scan through a set of serialized objects while ensuring low memory use. Do NOT store the references returned by next() anywhere as the contents of that reference will be changed by the next call to next().

      NOTE: The InputStream is closed after the last object is read.

      Type Parameters:
      BO - the object type, a subtype of BinaryObject.
      Parameters:
      boClass - the class to create.
      in - the input stream.
      length - the length of each object to read.
      Returns:
      an InlineScanner object for reading the objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".