Package org.datavec.api.records
Class Buffer
- java.lang.Object
-
- org.datavec.api.records.Buffer
-
- All Implemented Interfaces:
Cloneable,Comparable
public class Buffer extends Object implements Comparable, Cloneable
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(byte[] bytes)Append specified bytes to the buffervoidappend(byte[] bytes, int offset, int length)Append specified bytes to the buffer.Objectclone()intcompareTo(Object other)Define the sort order of the Buffer.voidcopy(byte[] bytes, int offset, int length)Copy the specified byte array to the Buffer.booleanequals(Object other)byte[]get()Get the data from the Buffer.intgetCapacity()Get the capacity, which is the maximum count that could handled without resizing the backing storage.intgetCount()Get the current count of the buffer.inthashCode()voidreset()Reset the buffer to 0 sizevoidset(byte[] bytes)Use the specified bytes array as underlying sequence.voidsetCapacity(int newCapacity)Change the capacity of the backing storage.StringtoString()StringtoString(String charsetName)Convert the byte buffer to a string an specific character encodingvoidtruncate()Change the capacity of the backing store to be the same as the current count of buffer.
-
-
-
Constructor Detail
-
Buffer
public Buffer()
Create a zero-count sequence.
-
Buffer
public Buffer(byte[] bytes)
Create a Buffer using the byte array as the initial value.- Parameters:
bytes- This array becomes the backing storage for the object.
-
Buffer
public Buffer(byte[] bytes, int offset, int length)Create a Buffer using the byte range as the initial value.- Parameters:
bytes- Copy of this array becomes the backing storage for the object.offset- offset into byte arraylength- length of data
-
-
Method Detail
-
set
public void set(byte[] bytes)
Use the specified bytes array as underlying sequence.- Parameters:
bytes- byte sequence
-
copy
public final void copy(byte[] bytes, int offset, int length)Copy the specified byte array to the Buffer. Replaces the current buffer.- Parameters:
bytes- byte array to be assignedoffset- offset into byte arraylength- length of data
-
get
public byte[] get()
Get the data from the Buffer.- Returns:
- The data is only valid between 0 and getCount() - 1.
-
getCount
public int getCount()
Get the current count of the buffer.
-
getCapacity
public int getCapacity()
Get the capacity, which is the maximum count that could handled without resizing the backing storage.- Returns:
- The number of bytes
-
setCapacity
public void setCapacity(int newCapacity)
Change the capacity of the backing storage. The data is preserved if newCapacity >= getCount().- Parameters:
newCapacity- The new capacity in bytes.
-
reset
public void reset()
Reset the buffer to 0 size
-
truncate
public void truncate()
Change the capacity of the backing store to be the same as the current count of buffer.
-
append
public void append(byte[] bytes, int offset, int length)Append specified bytes to the buffer.- Parameters:
bytes- byte array to be appendedoffset- offset into byte arraylength- length of data
-
append
public void append(byte[] bytes)
Append specified bytes to the buffer- Parameters:
bytes- byte array to be appended
-
compareTo
public int compareTo(Object other)
Define the sort order of the Buffer.- Specified by:
compareToin interfaceComparable- Parameters:
other- The other buffer- Returns:
- Positive if this is bigger than other, 0 if they are equal, and negative if this is smaller than other.
-
toString
public String toString(String charsetName) throws UnsupportedEncodingException
Convert the byte buffer to a string an specific character encoding- Parameters:
charsetName- Valid Java Character Set Name- Throws:
UnsupportedEncodingException
-
clone
public Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-