Java Utililty Methods ByteBuffer Save

List of utility methods to do ByteBuffer Save

Description

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

Method

voidsave(Path path, ByteBuffer bb)
Writes the remaining bytes of a byte buffer to the given file.
try (FileChannel fc = FileChannel.open(path, WRITE, CREATE)) {
    fc.truncate(bb.remaining());
    fc.write(bb);
voidsaveAsBMP(String filename, ByteBuffer pixel_data, int width, int height)
save As BMP
long before = System.currentTimeMillis();
int pad = 4 - (width * 3) % 4;
if (pad == 4)
    pad = 0;
int size = (width * 3 + pad) * height + 54;
ByteBuffer buffer = ByteBuffer.allocate(size);
buffer.put((byte) 0x42); 
buffer.put((byte) 0x4D); 
...
voidsaveAsFile(File targetFile, ByteBuffer bb)
save As File
FileOutputStream fos = new FileOutputStream(targetFile);
try {
    FileChannel wChannel = fos.getChannel();
    while (bb.hasRemaining()) {
        wChannel.write(bb);
    wChannel.close();
} finally {
...
FilesaveAsTempFile(ByteBuffer byteBuffer, String extension)
Saves the ByteBuffer as a temporary file in the default location
final File tempFile = File.createTempFile("tmp", extension);
try (FileOutputStream os = new FileOutputStream(tempFile)) {
    final FileChannel channel = os.getChannel();
    channel.write(byteBuffer);
    channel.force(true);
return tempFile;
voidsaveAsTGA(String filename, ByteBuffer pixel_data, int width, int height)
save As TGA
long before = System.currentTimeMillis();
try (FileOutputStream fout = new FileOutputStream(filename + ".tga")) {
    fout.write(0); 
    fout.write(0); 
    fout.write(2); 
    fout.write(0); 
    fout.write(0); 
    fout.write(0); 
...
StringsaveBytesBufferToFile(ByteBuffer buf, String filename)
save Bytes Buffer To File
return saveBytesBufferToFile(buf, new File(filename));
voidsavePageBitMask(ByteBuffer buffer, BitSet freePagesBitSet)
save Page Bit Mask
buffer.position(Integer.BYTES);
buffer.put(freePagesBitSet.toByteArray());
voidsaveStruct(ByteBuffer o, String[] struct, Object instance)
save Struct
try {
    Class instClass = instance.getClass();
    for (String s : struct) {
        String[] args = s.split(" ");
        if (args[0].equals("size")) {
        } else if (args[0].equals("data")) {
            o.put(Long.decode(args[1]).byteValue());
        } else if (args[0].equals("skip")) {
...