Package eu.woolplatform.utils.io
Class WritableByteBuffer
- java.lang.Object
-
- eu.woolplatform.utils.io.WritableByteBuffer
-
public class WritableByteBuffer extends Object
A byte buffer provides convenient methods to manipulate a byte array.
-
-
Constructor Summary
Constructors Constructor Description WritableByteBuffer(int capacity)Constructs a new byte buffer.WritableByteBuffer(WritableByteBuffer other)Constructs a new byte buffer and copies the content from another byte buffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(byte b)Appends the specified byte to the end of the buffer.voidappend(byte[] bs, int off, int len)Appends bytes from the specified byte array to the end of this buffer.voidappend(WritableByteBuffer other, int off, int len)Appends bytes from the specified byte buffer to the end of this buffer.voidclear()Removes all bytes from the buffer.Objectclone()byteget(int index)Returns the byte at the specified index.byteremoveFirst()Removes the first byte from this buffer and returns it.voidremoveHead(int n)Removes the first n bytes from this buffer.intsize()Returns the size of this buffer.byte[]toByteArray()Returns a byte array with the contents of this buffer.
-
-
-
Constructor Detail
-
WritableByteBuffer
public WritableByteBuffer(int capacity)
Constructs a new byte buffer. It will use a byte array with the specified capacity. The capacity will automatically grow if more space is needed.- Parameters:
capacity- the initial capacity
-
WritableByteBuffer
public WritableByteBuffer(WritableByteBuffer other)
Constructs a new byte buffer and copies the content from another byte buffer.- Parameters:
other- the other byte buffer
-
-
Method Detail
-
get
public byte get(int index)
Returns the byte at the specified index.- Parameters:
index- the index- Returns:
- the byte
-
size
public int size()
Returns the size of this buffer. This is not the capacity.- Returns:
- the size
-
clear
public void clear()
Removes all bytes from the buffer.
-
append
public void append(byte b)
Appends the specified byte to the end of the buffer.- Parameters:
b- the byte
-
append
public void append(byte[] bs, int off, int len)Appends bytes from the specified byte array to the end of this buffer.- Parameters:
bs- the byte arrayoff- the index of the first byte to appendlen- the number of bytes to append
-
append
public void append(WritableByteBuffer other, int off, int len)
Appends bytes from the specified byte buffer to the end of this buffer.- Parameters:
other- the byte bufferoff- the index of the first byte to appendlen- the number of bytes to append
-
removeHead
public void removeHead(int n)
Removes the first n bytes from this buffer.- Parameters:
n- the number of bytes to remove
-
removeFirst
public byte removeFirst()
Removes the first byte from this buffer and returns it.- Returns:
- the removed byte
-
toByteArray
public byte[] toByteArray()
Returns a byte array with the contents of this buffer.- Returns:
- the byte array
-
-