Java ByteBuffer Save save(Path path, ByteBuffer bb)

Here you can find the source of save(Path path, ByteBuffer bb)

Description

Writes the remaining bytes of a byte buffer to the given file.

License

Open Source License

Parameter

Parameter Description
path a parameter
bb a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void save(Path path, ByteBuffer bb) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;

import java.nio.file.Path;
import static java.nio.file.StandardOpenOption.*;

public class Main {
    /**//w  w w. j  a v a2 s.  c  o m
     * Writes the remaining bytes of a byte buffer to the given file. 
     * If the file already exists, it will be overwritten and its size will be 
     * truncated to the amount of remaining bytes in the given buffer.
     * 
     * @param path
     * @param bb
     * @throws IOException 
     */
    public static void save(Path path, ByteBuffer bb) throws IOException {
        try (FileChannel fc = FileChannel.open(path, WRITE, CREATE)) {
            fc.truncate(bb.remaining());
            fc.write(bb);
        }
    }
}

Related

  1. saveAsBMP(String filename, ByteBuffer pixel_data, int width, int height)
  2. saveAsFile(File targetFile, ByteBuffer bb)
  3. saveAsTempFile(ByteBuffer byteBuffer, String extension)
  4. saveAsTGA(String filename, ByteBuffer pixel_data, int width, int height)