Package org.jenkinsci.remoting.util
Class ByteBufferUtils
java.lang.Object
org.jenkinsci.remoting.util.ByteBufferUtils
Utility methods to help working with
ByteBuffer
s.- Since:
- 3.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ByteBuffer
A handy constant to use for no-op send/receive calls. -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBuffer
accumulate
(ByteBuffer src, ByteBuffer dst) Accumulate the given buffer into the current context.static ByteBuffer
duplicate
(ByteBuffer buffer) Duplicate a byte buffer for storing for future use.static String
getUTF8
(ByteBuffer src) Read from the source buffer a string that has been encoded in UTF-8 and prefixed by a two byte length.static void
put
(ByteBuffer src, ByteBuffer dst) Transfer bytes from src to dst.static void
putUTF8
(String src, ByteBuffer dst) Transfer a string into the destination buffer as a UTF-8 encoded string prefixed by a two byte length.static ByteBuffer
Wrap a string encoded as a UTF-8 string prefixed by a two byte length.
-
Field Details
-
EMPTY_BUFFER
A handy constant to use for no-op send/receive calls.
-
-
Method Details
-
put
Transfer bytes from src to dst. If the source has more bytes than the destination then only as many bytes as the destination has capacity to take will be transferred.- Parameters:
src
- the source.dst
- the destination.
-
putUTF8
Transfer a string into the destination buffer as a UTF-8 encoded string prefixed by a two byte length.- Parameters:
src
- the string to encode and copy.dst
- the destination.
-
getUTF8
Read from the source buffer a string that has been encoded in UTF-8 and prefixed by a two byte length.- Parameters:
src
- the source buffer.- Returns:
- the string.
- Throws:
BufferUnderflowException
- if the source buffer has not got the full string.
-
wrapUTF8
Wrap a string encoded as a UTF-8 string prefixed by a two byte length.- Parameters:
string
- the string.- Returns:
- a
ByteBuffer
containing the two byte length followed by the string encoded as UTF-8.
-
accumulate
Accumulate the given buffer into the current context. Allocation is performed only if needed.- Parameters:
src
- the buffer to accumulatedst
- the buffer to accumulate into- Returns:
- the accumulated buffer (may be
dst
or a new buffer ifdst
did not have sufficient capacity)
-
duplicate
Duplicate a byte buffer for storing for future use.- Parameters:
buffer
- the buffer to duplicate- Returns:
- the newly allocated buffer
-