Java Utililty Methods ByteBuffer Write

List of utility methods to do ByteBuffer Write

Description

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

Method

intwrite(WritableByteChannel out, ByteBuffer buffer)
write
int bytesWritten = 0;
while (buffer.hasRemaining()) {
    bytesWritten += out.write(buffer);
return bytesWritten;
voidwrite(WritableByteChannel socketChannel, SSLEngine engine, ByteBuffer plainOut, ByteBuffer cypherOut)
write
while (plainOut.hasRemaining()) {
    cypherOut.clear();
    SSLEngineResult result = engine.wrap(plainOut, cypherOut);
    switch (result.getStatus()) {
    case OK:
        cypherOut.flip();
        while (cypherOut.hasRemaining()) {
            socketChannel.write(cypherOut);
...
voidwriteAll(ByteBuffer buf, WritableByteChannel channel)
write All
while (buf.remaining() > 0)
    channel.write(buf);
voidwriteAll(ByteChannel channel, ByteBuffer buffer)
write All
while (buffer.hasRemaining()) {
    channel.write(buffer);
voidwriteAll(GatheringByteChannel ch, ByteBuffer... bbs)
write All
writeAll(ch, bbs, 0, bbs.length);
voidwriteAllToChannel(List buffers, WritableByteChannel channel)
write All To Channel
for (ByteBuffer buffer : buffers) {
    channel.write(buffer);
voidwriteBE(ByteBuffer bb, int elementWidth, long value)
write BE
final int p = bb.position();
for (int j = 0; j < elementWidth; j++) {
    bb.put(p + j, (byte) value);
    value >>>= 8;
bb.position(p + elementWidth);
voidwriteBER32(ByteBuffer buffer, int value)
write BER
buffer.put((byte) ((value >> 21) | 0x80));
buffer.put((byte) ((value >> 14) | 0x80));
buffer.put((byte) ((value >> 7) | 0x80));
buffer.put((byte) (value & 0x7F));
voidwriteBigInteger(ByteBuffer bb, BigInteger bigInteger, int length)
write Big Integer
byte[] bigInt = bigInteger.toByteArray();
int skipZeroPos = 0;
for (int i = 0; i < bigInt.length; i++) {
    if (bigInt[i] != 0) {
        break;
    skipZeroPos++;
byte[] tmp = new byte[bigInt.length - skipZeroPos];
System.arraycopy(bigInt, skipZeroPos, tmp, 0, tmp.length);
bigInt = tmp;
reverseBytes(bigInt);
int padByteLength = length - bigInt.length;
if (padByteLength > 0) {
    tmp = new byte[length];
    System.arraycopy(bigInt, 0, tmp, 0, bigInt.length);
    bigInt = tmp;
bb.put(bigInt);
booleanwriteBlock(String fileName, long startOffset, ByteBuffer buffer, Logger log)
Write received block to physical file on disk.
RandomAccessFile randomAccessFile = null;
File file = new File(fileName);
if (!file.exists()) {
    if (log != null)
        log.log(Level.WARNING, "Cannot write file \"" + fileName + "\" that does not exist");
    return false;
if (startOffset + buffer.remaining() > file.length()) {
...