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

voidwriteDouble(double v, ByteBuffer buffer)
write Double
writeLong(Double.doubleToRawLongBits(v), buffer);
voidwriteEmpty(final ByteBuffer buffer, final int type)
write Empty
buffer.put((byte) type);
buffer.put((byte) 0);
voidwriteFakeImageData(ByteBuffer out, int lzwMinCodeSize)
write Fake Image Data
verifyRemaining(out, 4);
verifyShortValues(lzwMinCodeSize);
out.put((byte) lzwMinCodeSize);
out.put((byte) 0x01);
out.put((byte) 0x01);
out.put((byte) 0x00);
voidwriteFFloat(ByteBuffer buffer, float value)
Writes a 4 byte float.
buffer.putInt(Float.floatToIntBits(value));
FilewriteFile(ByteBuffer data, File destination)
write File
try (FileChannel channel = FileChannel.open(destination.toPath(), StandardOpenOption.CREATE,
        StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
    channel.write(data);
return destination;
booleanwriteFile(File file, ByteBuffer bb)
write File
try {
    FileChannel wChannel = new FileOutputStream(file, false).getChannel();
    wChannel.write(bb);
    wChannel.close();
    return true;
} catch (IOException e) {
    e.printStackTrace();
return false;
voidwriteFile(File file, ByteBuffer buffer)
write File
boolean created = file.createNewFile();
assert created : file;
try (FileOutputStream fileWriter = new FileOutputStream(file)) {
    fileWriter.write(buffer.array(), 0, buffer.remaining());
booleanwriteFileFragment(FileChannel fc, long pos, ByteBuffer fragment)
write File Fragment
try {
    fc.position(pos);
    int size = fragment.remaining();
    if (fc.write(fragment) != size)
        return false;
    fc.force(false);
} catch (IOException ex) {
    ex.printStackTrace();
...
voidwriteFloat(ByteBuffer buffer, float f)
write Float
writeInt(buffer, Float.floatToIntBits(f));
intwriteFromBuffer(SocketChannel channel, ByteBuffer buf, int sleepMsecs)
write From Buffer
if (channel == null || buf.limit() == 0) {
    return -1;
int totWritten = 0;
buf.rewind();
while (totWritten < buf.limit()) {
    int nWritten;
    try {
...