Package org.jppf.utils
Class JPPFBuffer
java.lang.Object
org.jppf.utils.JPPFBuffer
buffer for the data read from or written to a socket connection.
- Author:
- Laurent Cohen, Domingos Creado
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInitialize this buffer.JPPFBuffer(byte[] buffer) Initialize this buffer with a specified buffer.JPPFBuffer(byte[] buffer, int length) Initialize this buffer with a specified buffer and buffer length.JPPFBuffer(String str) Initialize this buffer with the specified String, using UTF-8 encoding. -
Method Summary
Modifier and TypeMethodDescriptionasString()Transform this buffer into a string using UTF-8 encoding.byte[]Get the buffered data.intGet the length of the buffered data.intReturn the number of bytes available for writing in this buffer.intReturn the number of bytes available for reading in this buffer.reset()Reset this buffer's position to 0.voidsetBuffer(byte[] buffer) Set the buffered data.voidsetLength(int length) Set the length of the buffered data.
-
Field Details
-
buffer
public byte[] bufferThe actual buffer, intended to contain a serialized object graph. -
length
public int lengthThe length of the buffer. -
pos
public int posCurrent position in this buffer.
-
-
Constructor Details
-
JPPFBuffer
public JPPFBuffer()Initialize this buffer. -
JPPFBuffer
Initialize this buffer with the specified String, using UTF-8 encoding.- Parameters:
str- the string whose contents will be put into this buffer.
-
JPPFBuffer
public JPPFBuffer(byte[] buffer) Initialize this buffer with a specified buffer.- Parameters:
buffer- the buffer to use.
-
JPPFBuffer
public JPPFBuffer(byte[] buffer, int length) Initialize this buffer with a specified buffer and buffer length.- Parameters:
buffer- the buffer to use.length- the number of bytes to use in the buffer.
-
-
Method Details
-
setBuffer
public void setBuffer(byte[] buffer) Set the buffered data.- Parameters:
buffer- an array of bytes containing the data.
-
getBuffer
public byte[] getBuffer()Get the buffered data.- Returns:
- an array of bytes containing the data.
-
setLength
public void setLength(int length) Set the length of the buffered data.- Parameters:
length- the length as an int.
-
getLength
public int getLength()Get the length of the buffered data.- Returns:
- the length as an int.
-
remaining
public int remaining()Return the number of bytes available for writing in this buffer.- Returns:
- the available bytes as an int value.
-
remainingFromPos
public int remainingFromPos()Return the number of bytes available for reading in this buffer.- Returns:
- the available bytes as an int value.
-
reset
Reset this buffer's position to 0.- Returns:
- this buffer, for method call chaining.
-
asString
Transform this buffer into a string using UTF-8 encoding.- Returns:
- the content of this buffer as a string.
-