Java Utililty Methods File Write via ByteBuffer

List of utility methods to do File Write via ByteBuffer

Description

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

Method

intwriteFileNIO(String txt, File fyl)
Write a file using NIO.
return writeFileNIO(txt.getBytes(), fyl);
voidwriteFloat(OutputStream os, float val, ByteOrder bo)
Write a float to the OutputStream pointer respectively.
ByteBuffer bb = ByteBuffer.allocate(Float.SIZE / 8);
bb.order(bo);
bb.putFloat(val);
os.write(bb.array());
voidwriteInt(OutputStream os, int val, ByteOrder bo)
Write an int to the OutputStream and advance the stream pointer respectively.
ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / 8);
bb.order(bo);
bb.putInt(val);
os.write(bb.array());
voidwriteInt(OutputStream out, ByteOrder order, int i)
write Int
ByteBuffer buf = ByteBuffer.allocate(4);
buf.order(order);
buf.putInt(i);
out.write(buf.array(), buf.arrayOffset(), 4);
voidwriteInt(OutputStream out, int i)
write Int
byte[] bytes = new byte[Integer.BYTES];
ByteBuffer.wrap(bytes).putInt(i);
out.write(bytes);
longwriteInt(WritableByteChannel channel, int val)
write Int
ByteBuffer buf = ByteBuffer.allocate(4);
buf.putInt(val);
buf.rewind();
return writeByteBuffer(channel, buf, 4);
voidwriteInt(WritableByteChannel channel, int value)
Wrtie an integer value to a channel.
ByteBuffer buf = ByteBuffer.allocate(4);
buf.putInt(value);
buf.flip();
int count = 0;
while (count < 4) {
    int n = 0;
    while (n == 0)
        n = channel.write(buf);
...
voidwriteInt(WritableByteChannel channel, int value)
Writes an integer (32 bit) to the specified byte channel.
ByteBuffer bb4 = getByteBuffer(4);
bb4.position(0);
bb4.putInt(value);
bb4.position(0);
for (int cnt = 0; cnt < 4;) {
    int n = channel.write(bb4);
    cnt += n;
voidwriteLong(OutputStream in, long i)
Write the given int as a 8 byte long to the given outputStream.
ByteBuffer bb = ByteBuffer.allocate(8);
bb.putLong(i);
in.write(bb.array());
voidwriteLong(OutputStream os, Long d)
write Long
os.write(LONG);
byte[] b = new byte[8];
ByteBuffer.wrap(b).putLong(d);
os.write(b);