com.ohrasys.cad.gds
Class GDSByteConverter

java.lang.Object
  extended by com.ohrasys.cad.gds.GDSByteConverter

public class GDSByteConverter
extends java.lang.Object

A utility to convert byte arrays into java types and vice versa.

Since:
1.5

Constructor Summary
GDSByteConverter()
           
 
Method Summary
static java.io.ByteArrayOutputStream fromByte(byte data, java.io.ByteArrayOutputStream baos)
          Appends a java byte onto the ByteArrayOutputStream
static java.io.ByteArrayOutputStream fromDouble(double data, java.io.ByteArrayOutputStream baos)
          Appends a java double onto the ByteArrayOutputStream
static java.io.ByteArrayOutputStream fromFloat(float data, java.io.ByteArrayOutputStream baos)
          Appends a java float onto the ByteArrayOutputStream
static java.io.ByteArrayOutputStream fromInt(int data, java.io.ByteArrayOutputStream baos)
          Appends a java int onto the ByteArrayOutputStream
static java.io.ByteArrayOutputStream fromLong(long data, java.io.ByteArrayOutputStream baos)
          Appends a java long onto the ByteArrayOutputStream
static java.io.ByteArrayOutputStream fromShort(short data, java.io.ByteArrayOutputStream baos)
          Appends a java short onto the ByteArrayOutputStream
static byte readByte(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent byte.
static double readDouble(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent double.
static float readFloat(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent float.
static int readInt(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent int.
static long readLong(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent long.
static short readShort(java.io.InputStream in)
          Converts a byte array from the input stream into an equivalent short.
static byte toByte(byte[] bytes)
          Converts the byte array representation of the byte to an equivalent byte.
static double toDouble(byte[] bytes)
          Converts the byte array representation of the double to an equivalent double.
static float toFloat(byte[] bytes)
          Converts the byte array representation of the float to an equivalent float.
static int toInt(byte[] bytes)
          Converts the byte array representation of the int to an equivalent int.
static long toLong(byte[] bytes)
          Converts the byte array representation of the long to an equivalent long.
static short toShort(byte[] bytes)
          Converts the byte array representation of the short to an equivalent short.
 java.lang.String toString()
          Returns a string representation of this class
static byte[] writeByte(byte data)
          Converts a java byte into an equivalent byte array representation.
static byte[] writeDouble(double data)
          Converts a java double into an equivalent byte array representation.
static byte[] writeFloat(float data)
          Converts a java float into an equivalent byte array representation.
static byte[] writeInt(int data)
          Converts a java int into an equivalent byte array representation.
static byte[] writeLong(long data)
          Converts a java long into an equivalent byte array representation.
static byte[] writeShort(short data)
          Converts a java short into an equivalent byte array representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GDSByteConverter

public GDSByteConverter()
Method Detail

fromByte

public static java.io.ByteArrayOutputStream fromByte(byte data,
                                                     java.io.ByteArrayOutputStream baos)
Appends a java byte onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte appended to it.

fromDouble

public static java.io.ByteArrayOutputStream fromDouble(double data,
                                                       java.io.ByteArrayOutputStream baos)
Appends a java double onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte representation of the double appended to it.

fromFloat

public static java.io.ByteArrayOutputStream fromFloat(float data,
                                                      java.io.ByteArrayOutputStream baos)
Appends a java float onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte representation of the float appended to it.

fromInt

public static java.io.ByteArrayOutputStream fromInt(int data,
                                                    java.io.ByteArrayOutputStream baos)
Appends a java int onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte representation of the int appended to it.

fromLong

public static java.io.ByteArrayOutputStream fromLong(long data,
                                                     java.io.ByteArrayOutputStream baos)
Appends a java long onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte representation of the long appended to it.

fromShort

public static java.io.ByteArrayOutputStream fromShort(short data,
                                                      java.io.ByteArrayOutputStream baos)
Appends a java short onto the ByteArrayOutputStream

Parameters:
data - The data to write.
baos - The ByteArrayOutputStream
Returns:
The original output stream with the byte representation of the short appended to it.

readByte

public static byte readByte(java.io.InputStream in)
                     throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent byte.

Parameters:
in - The input stream from which to read.
Returns:
A byte from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

readDouble

public static double readDouble(java.io.InputStream in)
                         throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent double.

Parameters:
in - The input stream from which to read.
Returns:
A double from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

readFloat

public static float readFloat(java.io.InputStream in)
                       throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent float.

Parameters:
in - The input stream from which to read.
Returns:
A float from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

readInt

public static int readInt(java.io.InputStream in)
                   throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent int.

Parameters:
in - The input stream from which to read.
Returns:
A int from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

readLong

public static long readLong(java.io.InputStream in)
                     throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent long.

Parameters:
in - The input stream from which to read.
Returns:
A long from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

readShort

public static short readShort(java.io.InputStream in)
                       throws java.lang.NumberFormatException
Converts a byte array from the input stream into an equivalent short.

Parameters:
in - The input stream from which to read.
Returns:
A short from the input stream.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toByte

public static byte toByte(byte[] bytes)
                   throws java.lang.NumberFormatException
Converts the byte array representation of the byte to an equivalent byte.

Parameters:
bytes - The byte representation of the byte.
Returns:
The java representation of the byte.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toDouble

public static double toDouble(byte[] bytes)
                       throws java.lang.NumberFormatException
Converts the byte array representation of the double to an equivalent double.

Parameters:
bytes - The byte representation of the double.
Returns:
The java representation of the double.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toFloat

public static float toFloat(byte[] bytes)
                     throws java.lang.NumberFormatException
Converts the byte array representation of the float to an equivalent float.

Parameters:
bytes - The byte representation of the float.
Returns:
The java representation of the float.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toInt

public static int toInt(byte[] bytes)
                 throws java.lang.NumberFormatException
Converts the byte array representation of the int to an equivalent int.

Parameters:
bytes - The byte representation of the int.
Returns:
The java representation of the int.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toLong

public static long toLong(byte[] bytes)
                   throws java.lang.NumberFormatException
Converts the byte array representation of the long to an equivalent long.

Parameters:
bytes - The byte representation of the long.
Returns:
The java representation of the long.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

toShort

public static short toShort(byte[] bytes)
                     throws java.lang.NumberFormatException
Converts the byte array representation of the short to an equivalent short.

Parameters:
bytes - The byte representation of the short.
Returns:
The java representation of the short.
Throws:
java.lang.NumberFormatException - If the an error in processing occurs.

writeByte

public static byte[] writeByte(byte data)
Converts a java byte into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

writeDouble

public static byte[] writeDouble(double data)
Converts a java double into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

writeFloat

public static byte[] writeFloat(float data)
Converts a java float into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

writeInt

public static byte[] writeInt(int data)
Converts a java int into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

writeLong

public static byte[] writeLong(long data)
Converts a java long into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

writeShort

public static byte[] writeShort(short data)
Converts a java short into an equivalent byte array representation.

Parameters:
data - The data to convert.
Returns:
an equivalent byte array representation of the data.

toString

public java.lang.String toString()
Returns a string representation of this class

Overrides:
toString in class java.lang.Object
Returns:
The physical address of this instance