galaxy.lang
Class GBinary

java.lang.Object
  |
  +--galaxy.lang.GalaxyObject
        |
        +--galaxy.lang.BinaryObject
              |
              +--galaxy.lang.GBinary
All Implemented Interfaces:
java.lang.Cloneable

public class GBinary
extends BinaryObject


Fields inherited from class galaxy.lang.BinaryObject
data
 
Fields inherited from class galaxy.lang.GalaxyObject
GAL_BINARY, GAL_CLAUSE_FRAME, GAL_FLOAT, GAL_FLOAT_32, GAL_FLOAT_64, GAL_FRAME, GAL_FREE, GAL_INT, GAL_INT_16, GAL_INT_32, GAL_INT_64, GAL_KEYWORD, GAL_LIST, GAL_PRED_FRAME, GAL_PROXY, GAL_PTR, GAL_STRING, GAL_SYMBOL, GAL_TAG, GAL_TOKEN, GAL_TOPIC_FRAME, nameToType, type, typeToName
 
Constructor Summary
GBinary()
          Creates an empty array of bytes.
GBinary(byte[] data)
          This constructor creates an object that encapsulates a reference to the specified array.
GBinary(byte[] data, boolean makeCopy)
          This constructor creates an object that encapsulates the specified array.
 
Method Summary
 void append(byte[] b)
          Appends bytes to this object's byte array.
 byte[] getBytes()
           
 int getSize()
          Returns the size of this object's byte array.
static void main(java.lang.String[] args)
           
static byte[] readBinaryFile(java.lang.String file)
          Converts a binary file into an array of bytes.
 double[] toDoubleArray()
          Returns the byte array as an array of floats.
 java.lang.String toEncodedString()
          Returns this object's byte array as an encoded string.
 float[] toFloatArray()
          Returns the byte array as an array of floats.
 java.lang.String toFormattedString()
          Returns this object's byte array as a formatted string.
 int[] toIntArray()
          Returns the byte array as an array of integers.
 long[] toLongArray()
          Returns the byte array as an array of longs.
 short[] toShortArray()
          Returns the byte array as an array of shorts.
 java.lang.String toString()
          Returns this object's byte array as a string.
 
Methods inherited from class galaxy.lang.GalaxyObject
getType, getTypeForObject, getTypeName, nameType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GBinary

public GBinary()
Creates an empty array of bytes.

GBinary

public GBinary(byte[] data)
This constructor creates an object that encapsulates a reference to the specified array. If the array is null, an empty array is created.
Parameters:
data - the array

GBinary

public GBinary(byte[] data,
               boolean makeCopy)
        throws java.lang.Exception
This constructor creates an object that encapsulates the specified array. If the array is null, an empty array is created. An exception is thrown if there is an error while copying the array.
Parameters:
data - the array
makeCopy - if true, a copy of the array is stored. Otherwise, the reference to the array is stored.
Method Detail

getBytes

public byte[] getBytes()
Overrides:
getBytes in class BinaryObject

getSize

public int getSize()
Description copied from class: BinaryObject
Returns the size of this object's byte array.
Overrides:
getSize in class BinaryObject
Following copied from class: galaxy.lang.BinaryObject
Returns:
the array's size or -1 if the byte array does not exist

toString

public java.lang.String toString()
Description copied from class: BinaryObject
Returns this object's byte array as a string.
Overrides:
toString in class BinaryObject
Following copied from class: galaxy.lang.BinaryObject
Returns:
the string or null if the byte array does not exist

toEncodedString

public java.lang.String toEncodedString()
Description copied from class: BinaryObject
Returns this object's byte array as an encoded string.
Overrides:
toEncodedString in class BinaryObject
Following copied from class: galaxy.lang.BinaryObject
Returns:
the encoded string or null if the byte array does not exist

toFormattedString

public java.lang.String toFormattedString()
Description copied from class: BinaryObject
Returns this object's byte array as a formatted string.
Overrides:
toFormattedString in class BinaryObject
Following copied from class: galaxy.lang.BinaryObject
Returns:
the formatted string or null if the byte array does not exist

append

public void append(byte[] b)
Appends bytes to this object's byte array.
Overrides:
append in class BinaryObject
Parameters:
b - array of bytes to append

toFloatArray

public float[] toFloatArray()
Returns the byte array as an array of floats.
Returns:
the array of floats or null if the is an error

toDoubleArray

public double[] toDoubleArray()
Returns the byte array as an array of floats.
Returns:
the array of floats or null if the is an error

toShortArray

public short[] toShortArray()
Returns the byte array as an array of shorts.
Returns:
the array of shorts or null if the is an error

toIntArray

public int[] toIntArray()
Returns the byte array as an array of integers.
Returns:
the array of integers or null if the is an error

toLongArray

public long[] toLongArray()
Returns the byte array as an array of longs.
Returns:
the array of longs or null if the is an error

readBinaryFile

public static byte[] readBinaryFile(java.lang.String file)
                             throws java.io.IOException
Converts a binary file into an array of bytes.
Parameters:
file - the name of the binary file to convert
Returns:
the contents of the file in a byte array or null if there was an error

main

public static void main(java.lang.String[] args)