Package com.itextpdf.io.source
Class ByteBuffer
java.lang.Object
com.itextpdf.io.source.ByteBuffer
A growable byte buffer with append and byte-oriented conversion operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of bytes currently stored in this buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a buffer with the default initial capacity.ByteBuffer(int size) Creates a buffer with the requested initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionappend(byte b) Appends one byte, expanding the backing array when necessary.append(byte[] b) Appends all bytes from an array.append(byte[] b, int off, int len) Appends a range from a byte array.append(int b) Appends the low eight bits of an integer.Appends the ISO-8859-1 compatible byte representation of a string.appendHex(byte b) Appends two lowercase hexadecimal characters representing a byte.intcapacity()Gets the current backing-array capacity.byteget(int index) Gets a stored byte by index.static intgetHex(int v) Converts an ASCII hexadecimal digit to its numeric value.byte[]Gets the mutable backing array without copying.booleanisEmpty()Tests whether this buffer has no stored bytes.reset()Discards all stored bytes while retaining the backing array.intsize()Gets the number of bytes stored in this buffer.booleanstartsWith(byte[] b) Tests whether the stored bytes begin with a sequence.byte[]Copies all stored bytes.byte[]toByteArray(int off, int len) Copies a range from the backing array.
-
Field Details
-
count
protected int countThe number of bytes currently stored in this buffer.
-
-
Constructor Details
-
ByteBuffer
public ByteBuffer()Creates a buffer with the default initial capacity. -
ByteBuffer
public ByteBuffer(int size) Creates a buffer with the requested initial capacity.- Parameters:
-
size- the initial capacity; values below one use the default capacity
-
-
Method Details
-
getHex
public static int getHex(int v) Converts an ASCII hexadecimal digit to its numeric value.- Parameters:
-
v- the character value to convert - Returns:
-
a value from
0through15, or-1whenvis not hexadecimal
-
append
Appends one byte, expanding the backing array when necessary.- Parameters:
-
b- the byte to append - Returns:
- this buffer
-
append
Appends a range from a byte array.- Parameters:
-
b- the source array -
off- the zero-based source offset -
len- the number of bytes to append - Returns:
- this buffer; invalid ranges and zero lengths leave it unchanged
-
append
Appends all bytes from an array.- Parameters:
-
b- the source array - Returns:
- this buffer
-
append
Appends the low eight bits of an integer.- Parameters:
-
b- the value whose low byte is appended - Returns:
- this buffer
-
append
Appends the ISO-8859-1 compatible byte representation of a string.- Parameters:
-
str- the string to append - Returns:
- this buffer
-
appendHex
Appends two lowercase hexadecimal characters representing a byte.- Parameters:
-
b- the byte to encode - Returns:
- this buffer
-
get
public byte get(int index) Gets a stored byte by index.- Parameters:
-
index- the zero-based index - Returns:
-
the byte at
index - Throws:
-
IndexOutOfBoundsException- ifindexis at or beyondsize()
-
getInternalBuffer
public byte[] getInternalBuffer()Gets the mutable backing array without copying.- Returns:
-
the backing array, whose length may exceed
size()
-
size
public int size()Gets the number of bytes stored in this buffer.- Returns:
- the logical byte count
-
isEmpty
public boolean isEmpty()Tests whether this buffer has no stored bytes.- Returns:
-
truewhensize()is zero
-
capacity
public int capacity()Gets the current backing-array capacity.- Returns:
- the number of bytes the backing array can hold without growing
-
reset
Discards all stored bytes while retaining the backing array.- Returns:
- this buffer
-
toByteArray
public byte[] toByteArray(int off, int len) Copies a range from the backing array.- Parameters:
-
off- the zero-based source offset -
len- the number of bytes to copy - Returns:
- a new array containing the requested bytes
-
toByteArray
public byte[] toByteArray()Copies all stored bytes.- Returns:
-
a new array containing bytes from zero through
size()
-
startsWith
public boolean startsWith(byte[] b) Tests whether the stored bytes begin with a sequence.- Parameters:
-
b- the candidate prefix - Returns:
-
truewhen this buffer starts withb
-