Package net.mtrop.doom.object
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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
BinaryObject.InlineScanner<BO extends BinaryObject>
A deserializing scanner iterator that returns the same object instance with its contents changed.static class
static class
BinaryObject.Scanner<BO extends BinaryObject>
A deserializing scanner iterator that returns independent instances of objects.static class
static interface
BinaryObject.Transformer<BO extends BinaryObject>
Transformer interface for transform calls. -
Method Summary
Modifier and TypeMethodDescriptionstatic <BO extends BinaryObject>
BOCreates a single object of a specific class from a serialized byte array.static <BO extends BinaryObject>
BO[]Creates an amount of objects of a specific class from a serialized byte array.default void
fromBytes
(byte[] data) Reads in the byte representation of this object and sets its fields.static <BO extends BinaryObject>
BinaryObject.InlineScanner<BO>inlineScanner
(Class<BO> boClass, InputStream in, int length) Creates a deserializing scanner iterator that returns the same object instance with its contents changed.static <BO extends BinaryObject>
BOCreates a single object of a specific class from from aFile
.static <BO extends BinaryObject>
BO[]Creates an amount of objects of a specific class from aFile
.static <BO extends BinaryObject>
BOread
(Class<BO> boClass, InputStream in) Creates a single object of a specific class from from anInputStream
.static <BO extends BinaryObject>
BO[]read
(Class<BO> boClass, InputStream in, int count) Creates an amount of objects of a specific class from anInputStream
.void
readBytes
(InputStream in) Reads from anInputStream
and sets this object's fields.default void
Reads from aFile
and sets this object's fields.static <BO extends BinaryObject>
BinaryObject.Scanner<BO>scanner
(Class<BO> boClass, InputStream in, int length) Creates a deserializing scanner iterator that returns independent instances of objects.default byte[]
toBytes()
Gets the byte representation of this object.static <BO extends BinaryObject>
byte[]toBytes
(BO[] data) Converts an array of BinaryObjects into bytes.void
writeBytes
(OutputStream out) Writes this object to anOutputStream
.default void
Writes this object to aFile
.default void
Writes this object to aFile
.
-
Method Details
-
readBytes
Reads from anInputStream
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
- theInputStream
to read from.- Throws:
IOException
- if a read error occurs.
-
readFile
Reads from aFile
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
- theFile
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
Writes this object to anOutputStream
.- Parameters:
out
- theOutputStream
to write to.- Throws:
IOException
- if a write error occurs.
-
writeFile
Writes this object to aFile
. The file's contents are overwritten.- Parameters:
file
- theFile
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
Writes this object to aFile
.- Parameters:
file
- theFile
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
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
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
Creates a single object of a specific class from a serialized byte array.- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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
Creates a single object of a specific class from from anInputStream
.- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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
Creates a single object of a specific class from from aFile
.- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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 ofBinaryObject
.- 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 anInputStream
.- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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 aFile
.- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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 ofBinaryObject
.- 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 bynext()
anywhere as the contents of that reference will be changed by the next call tonext()
.NOTE: The InputStream is closed after the last object is read.
- Type Parameters:
BO
- the object type, a subtype ofBinaryObject
.- 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".
-