tcl.lang
Class TclByteArray

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

public class TclByteArray
extends Object
implements InternalRep

This class implements the binary data object type in Tcl.


Method Summary
static String decodeToString(Interp interp, TclObject tobj, String tclEncoding)
          Interpret the bytes in the byte array according to the specified tcl encoding and return the corresponding string.
 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.
 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

dispose

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

Specified by:
dispose in interface InternalRep

toString

public 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 Object
Returns:
the string representation of the TclByteArray, calculated by copying each byte into the lower byte of each character (Tcl's 'identity' encoding)

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.

Parameters:
interp - the current interpreter
tobj - object in which to change the byte array length. Object is converted to a TclByteArray
length - new length of the array
Returns:
the byte array

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.

decodeToString

public static String decodeToString(Interp interp,
                                    TclObject tobj,
                                    String tclEncoding)
Interpret the bytes in the byte array according to the specified tcl encoding and return the corresponding string.

Parameters:
interp - the current interpreter
tobj - the object, which is converted to a TclByteArray if necessary
tclEncoding - Tcl encoding in which to decode to String. 'identity', 'binary' and null all imply that the string will be made of chars whose lower byte is the corresponding byte from the array.
Returns:
the decoded string


Copyright © 2015. All rights reserved.