Java ByteBuffer Write writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)

Here you can find the source of writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)

Description

Write an entire ByteBuffer into a file.

License

LGPL

Parameter

Parameter Description
file a file to read in.
buffer a <code>ByteBuffer</code> to be written into the file.

Exception

Parameter Description
IOException if an I/O exception occures.

Declaration

public static int writeByteBuffer(RandomAccessFile file, ByteBuffer buffer) throws IOException 

Method Source Code

//package com.java2s;
/**/*from w  ww  .ja v a2 s .c om*/
 *             NativeFmod Project
 *
 * Want to use FMOD API (www.fmod.org) in the Java language ? NativeFmod is made for you.
 * Copyright ? 2004-2007 J?r?me JOUVIE (Jouvieje)
 *
 * Created on 28 avr. 2004
 * @version NativeFmod v3.4 (for FMOD v3.75)
 * @author J?r?me JOUVIE (Jouvieje)
 *
 *
 * WANT TO CONTACT ME ?
 * E-mail :
 *       jerome.jouvie@gmail.com
 * My web sites :
 *       http://jerome.jouvie.free.fr/
 *
 *
 * INTRODUCTION
 * Fmod is an API (Application Programming Interface) that allow you to use music
 * and creating sound effects with a lot of sort of musics.
 * Fmod is at :
 *       http://www.fmod.org/
 * The reason of this project is that Fmod can't be used in Java direcly, so I've created
 * NativeFmod project.
 *
 *
 * GNU LESSER GENERAL PUBLIC LICENSE
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA
 */

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

public class Main {
    /**
     * Write an entire <code>ByteBuffer</code> into a file.<BR>
     * @param file a file to read in.
     * @param buffer a <code>ByteBuffer</code> to be written into the file.
     * @throws IOException if an I/O exception occures.
     */
    public static int writeByteBuffer(RandomAccessFile file, ByteBuffer buffer) throws IOException {
        return file.getChannel().write(buffer);
    }

    /**
     * Write a part of a <code>ByteBuffer</code> into a file.
     * @param file a file to read in.
     * @param buffer a <code>ByteBuffer</code> to be written into the file.
     * @param length number of bytes to be written into the file.
     * @throws IOException if an I/O exception occures.
     */
    public static int writeByteBuffer(RandomAccessFile file, ByteBuffer buffer, int length) throws IOException {
        ByteBuffer view = buffer.duplicate();
        view.limit(view.position() + length);
        int written = file.getChannel().write(view);
        buffer.position(view.position());
        return written;
    }
}

Related

  1. writeByteArray(byte[] array, ByteBuffer out)
  2. writeByteArray(byte[] data, ByteBuffer buffer)
  3. writeByteArray(ByteBuffer byteBuffer, byte[] bytes)
  4. writeByteArray(ByteBuffer logBuf, byte[] b)
  5. writeByteBuffer(ByteBuffer bbuf, String filename)
  6. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  7. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  8. writeByteString(ByteBuffer byteBuffer, String value)
  9. writeCDouble(ByteBuffer buffer, double value)