CkByteData Java Reference Documentation

CkByteData

Current Version: 10.0.0

Represents a chunk of byte data and provides methods for accessing it, adding to it, or saving and loading from files.

Object Creation

CkByteData obj = new CkByteData();

Properties

SecureClear
boolean get_SecureClear();
void put_SecureClear(boolean newVal);
Introduced in version 9.5.0.73

If set to true, then memory is always first overwritten with zero bytes prior to deallocation. The default value of this property is false.

top

Methods

append
void append(CkByteData db);

Appends byte data to the data already contained in the object.

top
append2
void append2(byte[] pByteData, int szByteData);

Appends bytes to the data already contained in the object.

top
appendChar
void appendChar(byte ch);

Appends a single byte.

top
appendCharN
void appendCharN(byte ch, int numTimes);

Appends a single char N times. The equivalent of calling appendChar N times.

top
appendEncoded
void appendEncoded(String str, String encoding);

Appends binary data from an encoded string. The encoding can be specified as "hex", "base64", "url", "quoted-printable", "modBase64", "base58", or "base32". The input string is decoded from the specified encoding and the binary data is appended to the calling object's content.

top
appendFile
boolean appendFile(String path);

Opens a file for binary read, appends the file contents, and closes the file.

top
appendInt
void appendInt(int intValue, boolean littleEndian);

Appends a 32-bit signed integer (4 bytes) to the data already contained in the object. littleEndian determines whether the big endian or little endian byte ordering is used.

top
appendRandom
void appendRandom(int numBytes);

Appends numBytes random bytes to the data already contained within the object.

top
appendRange
void appendRange(CkByteData byteData, int index, int numBytes);

Appends a range of bytes from byteData to the data contained withing the caller. The first byte is at index 0.

top
appendShort
void appendShort(short shortValue, boolean littleEndian);

Appends a 16-bit signed integer (2 bytes) to the data already contained in the object. littleEndian determines whether the big endian or little endian byte ordering is used.

top
appendStr
void appendStr(String str);

Appends a null-terminated string to the data, without including the terminating null.

top
beginsWith
boolean beginsWith(CkByteData byteDataObj);

Returns true if the caller's data begins with the exact bytes contained within byteDataObj.

top
beginsWith2
boolean beginsWith2(byte[] pByteData, int szByteData);

Returns true if the caller's data begins with specified bytes.

top
byteSwap4321
void byteSwap4321();

4321 byte swaps the data contained within the object.

top
clear
void clear();

Clears the CkByteData object of all data. The internal memory is deallocated. To clear without deallocating, call dropData instead.

top
dropData
void dropData();
Introduced in version 9.5.0.91

Sets the size of the data to 0. Does not deallocate the existing internal buffer. (This is a fast way of "clearing" the CkByteData object, such that the existing data remains in memory and is overwritten on the next append.)

If the SecureClear property is set to true, then the internal memory buffer is zeroed out before resetting the size to 0.

top
encode
void encode(String encoding, CkString str);

Encodes binary data according to the encoding requested. The encoding can be specified as "hex", "base64", "url", "quoted-printable", "modBase64", "base58", "base32", "qp-", "url_rfc1738", "url_rfc2396", or "url_rfc3986".

top
ensureBuffer
boolean ensureBuffer(int expectedNumBytes);

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

If the internal buffer is already larger than the expectedNumBytes then nothing happens. The existing internal buffer is kept.

Returns true for success, false for failure.

top
equals
boolean equals(CkByteData compareBytes);

Returns true if compareBytes contains exactly the same content as the caller. Otherwise returns false.

top
equals2
boolean equals2(byte[] pCompareBytes, int numBytes);

Returns true if the bytes pointed to by pCompareBytes contains exactly the same content as the caller. Otherwise returns false.

top
findBytes
int findBytes(CkByteData byteDataObj);

Locates the first occurrence of the bytes contained in byteDataObj and returns the index of where these bytes occur in the caller's data. Returns -1 if not found.

top
findBytes2
int findBytes2(byte[] findBytes, int findBytesLen);

Locates the first occurrence of the specified bytes and returns the index of where these bytes occur in the caller's data. Returns -1 if not found.

top
getByte
byte getByte(int byteIndex);

Returns the Nth byte of the binary data. The 1st byte is at index 0.

top
getChar
byte getChar(int byteIndex);

Returns the Nth byte of the binary content as a "char". The 1st byte is at index 0.

top
getData
byte[] getData();

Returns a pointer to the internal buffer. Be careful with this method because if additional data is appended, the data within the object may be relocated and the pointer may cease to be valid.

top
getDataAt
byte[] getDataAt(int byteIndex);

Same as getData, except it gets a pointer to the data at a byte offset. (0 = the start of buffer)

top
getInt
int getInt(int byteIndex);

Returns the 4-byte integer located at a specific byte index.

top
getRange
byte[] getRange(int byteIndex, int numBytes);

Copies a range of bytes to a separate internal memory buffer and returns the pointer to the bytes. The returned pointer is only valid while the object exists. Also, any subsequent calls to getRange, getRangeStr, or to_s will invalidate the buffer.

top
getSize
int getSize();

Returns the number of bytes in the data buffer.

top
is7bit
boolean is7bit();

Returns true if all the bytes are in the range 0x00 to 0x7F.

top
loadFile
boolean loadFile(String path);

Equivalent to clear() followed by appendFile().

top
pad
void pad(int blockSize, int paddingScheme);

Pads the data to a multiple of the blockSize using a cryptographic padding scheme specified by paddingScheme. The possible integer values for paddingScheme are the same as those listed for the PaddingScheme property of the CkCrypt2 class.

top
removeChunk
void removeChunk(int startIndex, int numBytes);

Removes (discards) a range from the data.

top
replaceChar
void replaceChar(byte existingByteValue, byte replacementByteValue);

Replaces all occurrences of existingByteValue with replacementByteValue.

top
saveFile
boolean saveFile(String path);

Saves the byte data to a file. If the file already exists, it will be overwritten.

top
shorten
void shorten(int numBytes);

Discards N bytes from the end of the data.

top
to_ws
byte[] to_ws(String charset);

To be documented soon...

top
unpad
void unpad(int blockSize, int paddingScheme);

Unpads the data from a multiple of the blockSize to the original data size using a cryptographic padding scheme specified by paddingScheme. The possible integer values for paddingScheme are the same as those listed for the PaddingScheme property of the CkCrypt2 class.

top