Java Utililty Methods ByteBuffer Put

List of utility methods to do ByteBuffer Put

Description

The list of methods to do ByteBuffer Put are organized into topic(s).

Method

voidskipBlank(ByteBuffer input)
skip Blank
if (input.get() != ' ') {
    throw new IOException("Parser error reading input from the server: expected a blank space");
ByteArrayInputStreamtoByteArrayInputStream(ByteBuffer buffer)
to Byte Array Input Stream
if (buffer.hasArray()) {
    return new ByteArrayInputStream(buffer.array(), buffer.arrayOffset() + buffer.position(),
            buffer.remaining());
} else {
    return new ByteArrayInputStream(toBytes(buffer));
ByteBuffertoByteBuffer(InputStream inputStream)
to Byte Buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int l;
while ((l = inputStream.read(buffer)) != -1) {
    baos.write(buffer, 0, l);
return ByteBuffer.wrap(baos.toByteArray());
ByteBuffertoByteBuffer(String input)
to Byte Buffer
return ByteBuffer.wrap(input.getBytes(StandardCharsets.UTF_8));
SSLEngineResultwrap(ByteBuffer byteBuffer, ByteBuffer outputBB, SSLEngine sslEngine)
Encrypt bytes.
outputBB.clear();
SSLEngineResult result = sslEngine.wrap(byteBuffer, outputBB);
outputBB.flip();
return result;
voidwrite(ByteBuffer buffer, DataOutput out)
write
if (buffer.hasArray()) {
    out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
} else {
    for (int i = buffer.position(); i < buffer.limit(); i++) {
        out.writeByte(buffer.get(i));
voidwrite(ByteBuffer byteBuffer, OutputStream outputStream)
Write the contents of the given ByteBuffer into a OutputStream .
while (byteBuffer.remaining() > 0) {
    outputStream.write(byteBuffer.get());
voidwriteByteBufferList(List list, DataOutputStream os)
write Byte Buffer List
if (list == null) {
    os.writeInt(-1);
    return;
os.writeInt(list.size());
for (int k = 0; k < list.size(); k++) {
    writeByteBuffer(list.get(k), os);
voidwriteBytes(OutputStream os, ByteBuffer buffer)
Writes the buffer content to the output stream.
WritableByteChannel ch = Channels.newChannel(os);
ch.write(buffer);
voidwriteFully(ByteBuffer buffer, OutputStream os)
Writes all the remaining bytes of the ByteBuffer to the given OutputStream .
if (!buffer.hasArray()) {
    throw new IllegalArgumentException("This only works with buffer that have a backing array");
os.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
buffer.position(buffer.limit());