Package org.cakelab.blender.io.util
Class Identifier
- java.lang.Object
-
- org.cakelab.blender.io.util.Identifier
-
public class Identifier extends java.lang.Object
This class implements an abstraction layer to 4 byte character identifiers used for block codes and markers in StructDNA. It provides convenient methods to read a code from file and compare it to some code you expect.Note on ID2 Values
Blender uses a couple of IDs with just two significant positions, such as SC.. etc. Those IDs always have 4 bytes since they are used as block codes. Since codes are stored as byte array (ASCII string), byte order of the file will not influence the order of the bytes in the code. Internally blender converts codes to system byte order to allow comparison to globally defined constants. Because we compare codes based on the bytes given, we don't have to consider byte order here.- Author:
- homac
-
-
Constructor Summary
Constructors Constructor Description Identifier()
Identifier(byte[] code)
Identifier(java.lang.String strCode)
This constructor creates an identifier using the characters in the given string interpreted as ASCII.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
consume(CDataReadWriteAccess in, Identifier expected)
This reads a code from the input stream and compares it to the 'expected' value.boolean
equals(java.lang.Object obj)
byte[]
getData()
Returns the sequence of bytes which represents the actual code.java.lang.String
getDataString()
int
hashCode()
void
read(CDataReadWriteAccess in)
This method reads the code from the give input stream.java.lang.String
toString()
void
write(CDataReadWriteAccess io)
-
-
-
Method Detail
-
read
public void read(CDataReadWriteAccess in) throws java.io.IOException
This method reads the code from the give input stream.- Parameters:
in
-- Throws:
java.io.IOException
-
write
public void write(CDataReadWriteAccess io) throws java.io.IOException
- Throws:
java.io.IOException
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
consume
public void consume(CDataReadWriteAccess in, Identifier expected) throws java.io.IOException
This reads a code from the input stream and compares it to the 'expected' value. A mismatch is considered as an I/O error and treated with an IOException.- Parameters:
in
-expected
-- Throws:
java.io.IOException
-
getDataString
public java.lang.String getDataString()
-
getData
public byte[] getData()
Returns the sequence of bytes which represents the actual code.
-
-