tcl.lang
Class TclByteArray

java.lang.Object
  extended by tcl.lang.TclByteArray
All Implemented Interfaces:
InternalRep

public class TclByteArray
extends java.lang.Object
implements InternalRep

This class implements the binary data object type in Tcl.


Method Summary
 void dispose()
          Implement this no-op for the InternalRep interface.
 InternalRep duplicate()
          Returns a duplicate of the current object.
static byte[] getBytes(Interp interp, TclObject tobj)
          Returns the bytes of a ByteArray object.
static int getLength(Interp interp, TclObject tobj)
          Queries the length of the byte array.
static TclObject newInstance()
          Creates a new instance of a TclObject with an empty TclByteArray internal rep.
static TclObject newInstance(byte[] b)
          Creates a new instance of a TclObject with a TclByteArray internal rep.
static TclObject newInstance(byte[] b, int position, int length)
          Creates a new instance of a TclObject with a TclByteArray internal rep.
static byte[] setLength(Interp interp, TclObject tobj, int length)
          This method changes the length of the byte array for this object.
 java.lang.String toString()
          Called to query the string representation of the Tcl object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

duplicate

public InternalRep duplicate()
Returns a duplicate of the current object.

Specified by:
duplicate in interface InternalRep
Parameters:
obj - the TclObject that contains this internalRep.

dispose

public void dispose()
Implement this no-op for the InternalRep interface.

Specified by:
dispose in interface InternalRep

toString

public java.lang.String toString()
Called to query the string representation of the Tcl object. This method is called only by TclObject.toString() when TclObject.stringRep is null.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of the Tcl object.

newInstance

public static TclObject newInstance(byte[] b,
                                    int position,
                                    int length)
Creates a new instance of a TclObject with a TclByteArray internal rep.

Returns:
the TclObject with the given byte array value.

newInstance

public static TclObject newInstance(byte[] b)
Creates a new instance of a TclObject with a TclByteArray internal rep.

Returns:
the TclObject with the given byte array value.

newInstance

public static TclObject newInstance()
Creates a new instance of a TclObject with an empty TclByteArray internal rep.

Returns:
the TclObject with the empty byte array value.

setLength

public static byte[] setLength(Interp interp,
                               TclObject tobj,
                               int length)
This method changes the length of the byte array for this object. Once the caller has set the length of the array, it is acceptable to directly modify the bytes in the array up until Tcl_GetStringFromObj() has been called on this object. Results: The new byte array of the specified length. Side effects: Allocates enough memory for an array of bytes of the requested size. When growing the array, the old array is copied to the new array; new bytes are undefined. When shrinking, the old array is truncated to the specified length.


getLength

public static final int getLength(Interp interp,
                                  TclObject tobj)
Queries the length of the byte array. If tobj is not a byte array object, an attempt will be made to convert it to a byte array.

Parameters:
interp - current interpreter.
tobj - the TclObject to use as a byte array.
Returns:
the length of the byte array.
Throws:
TclException - if tobj is not a valid byte array.

getBytes

public static byte[] getBytes(Interp interp,
                              TclObject tobj)
Returns the bytes of a ByteArray object. If tobj is not a ByteArray object, an attempt will be made to convert it to a ByteArray.

Parameters:
interp - the current interpreter.
tobj - the byte array object.
Returns:
a byte array.
Throws:
TclException - if tobj is not a valid ByteArray.