org.jouvieje.fmodex.utils
Class FileIOUtils

java.lang.Object
  extended byorg.jouvieje.fmodex.utils.FileIOUtils
All Implemented Interfaces:
SizeOfPrimitive

public class FileIOUtils
extends java.lang.Object
implements SizeOfPrimitive

This class is an utility to read/write from a RandomAccessFile.


Field Summary
 
Fields inherited from interface org.jouvieje.fmodex.utils.SizeOfPrimitive
SIZEOF_BYTE, SIZEOF_CHAR, SIZEOF_DOUBLE, SIZEOF_FLOAT, SIZEOF_INT, SIZEOF_LONG, SIZEOF_SHORT
 
Constructor Summary
FileIOUtils()
           
 
Method Summary
 void freeMemory()
          Call this to free internal memory allocated
 byte readByte(java.io.RandomAccessFile file)
          Read a simple byte into the file.
 void readByteArray(java.io.RandomAccessFile file, byte[] datas, int offset, int nbBytes)
          Read a byte[] from a file.
 byte[] readByteArray(java.io.RandomAccessFile file, int nbBytes)
          Read a byte[] from a file.
 void readByteBuffer(java.io.RandomAccessFile file, java.nio.ByteBuffer buffer, int nbBytes)
          Read a ByteBuffer from a file.
 java.nio.ByteBuffer readByteBuffer(java.io.RandomAccessFile file, int nbBytes)
          Read a ByteBuffer from a file.
 char readChar(java.io.RandomAccessFile file)
          Read a char from 2 bytes of the file.
 double readDouble(java.io.RandomAccessFile file)
          Read a double from 8 bytes of the file.
 float readFloat(java.io.RandomAccessFile file)
          Read a float from 4 bytes of the file.
 int readInt(java.io.RandomAccessFile file)
          Read an int from 4 bytes of the file.
 long readLong(java.io.RandomAccessFile file)
          Read a long from 8 bytes of the file.
 short readShort(java.io.RandomAccessFile file)
          Read a short from 2 bytes of the file.
 void writeByte(java.io.RandomAccessFile file, byte value)
          Write a simple byte into the file.
 void writeByteArray(java.io.RandomAccessFile file, byte[] datas)
          Write an entire byte[] into the file.
 void writeByteArray(java.io.RandomAccessFile file, byte[] datas, int offset, int length)
          Write a part of a byte[] into the file.
 int writeByteBuffer(java.io.RandomAccessFile file, java.nio.ByteBuffer buffer)
          Write an entire ByteBuffer into a file.
 int writeByteBuffer(java.io.RandomAccessFile file, java.nio.ByteBuffer buffer, int length)
          Write a part of a ByteBuffer into a file.
 void writeChar(java.io.RandomAccessFile file, char value)
          Convert the char in 2 bytes and write them into the file.
 void writeDouble(java.io.RandomAccessFile file, double value)
          Convert the double in 8 bytes and write them into the file.
 void writeFloat(java.io.RandomAccessFile file, float value)
          Convert the float in 4 bytes and write them into the file.
 void writeInt(java.io.RandomAccessFile file, int value)
          Convert the int in 4 bytes and write them into the file.
 void writeLong(java.io.RandomAccessFile file, long value)
          Convert the long in 8 bytes and write them into the file.
 void writeShort(java.io.RandomAccessFile file, short value)
          Convert the short in 2 bytes and write them into the file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileIOUtils

public FileIOUtils()
Method Detail

freeMemory

public void freeMemory()
Call this to free internal memory allocated


readByte

public byte readByte(java.io.RandomAccessFile file)
              throws java.io.IOException
Read a simple byte into the file.

Returns:
the byte read from the file
Throws:
java.io.IOException - if an I/O error occures.

readShort

public short readShort(java.io.RandomAccessFile file)
                throws java.io.IOException
Read a short from 2 bytes of the file.

Returns:
the short read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readChar

public char readChar(java.io.RandomAccessFile file)
              throws java.io.IOException
Read a char from 2 bytes of the file.

Returns:
the char read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readInt

public int readInt(java.io.RandomAccessFile file)
            throws java.io.IOException
Read an int from 4 bytes of the file.

Returns:
the int read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readFloat

public float readFloat(java.io.RandomAccessFile file)
                throws java.io.IOException
Read a float from 4 bytes of the file.

Returns:
the float read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readLong

public long readLong(java.io.RandomAccessFile file)
              throws java.io.IOException
Read a long from 8 bytes of the file.

Returns:
the long read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readDouble

public double readDouble(java.io.RandomAccessFile file)
                  throws java.io.IOException
Read a double from 8 bytes of the file.

Returns:
the double read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readByteArray

public byte[] readByteArray(java.io.RandomAccessFile file,
                            int nbBytes)
                     throws java.io.IOException
Read a byte[] from a file.

Parameters:
nbBytes - number of bytes to read.
Returns:
the byte[] read from the file.
Throws:
java.io.IOException - if an I/O error occures.

readByteArray

public void readByteArray(java.io.RandomAccessFile file,
                          byte[] datas,
                          int offset,
                          int nbBytes)
                   throws java.io.IOException
Read a byte[] from a file.

Parameters:
datas - byte[] into which the data is read.
offset - offset
nbBytes - number of bytes to be read.
Throws:
java.io.IOException - if an I/O error occures.

readByteBuffer

public java.nio.ByteBuffer readByteBuffer(java.io.RandomAccessFile file,
                                          int nbBytes)
                                   throws java.io.IOException
Read a ByteBuffer from a file.

Parameters:
nbBytes - number of bytes to be read.
Returns:
the ByteBuffer read from the file
Throws:
java.io.IOException - if an I/O error occures.

readByteBuffer

public void readByteBuffer(java.io.RandomAccessFile file,
                           java.nio.ByteBuffer buffer,
                           int nbBytes)
                    throws java.io.IOException
Read a ByteBuffer from a file.

Parameters:
buffer - ByteBuffer into which the data is read.
nbBytes - number of bytes to be read.
Throws:
java.io.IOException - if an I/O error occures.

writeByte

public void writeByte(java.io.RandomAccessFile file,
                      byte value)
               throws java.io.IOException
Write a simple byte into the file.

Parameters:
file - a file to read in.
value - a byte to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeShort

public void writeShort(java.io.RandomAccessFile file,
                       short value)
                throws java.io.IOException
Convert the short in 2 bytes and write them into the file.

Parameters:
file - a file to read in.
value - a short to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeChar

public void writeChar(java.io.RandomAccessFile file,
                      char value)
               throws java.io.IOException
Convert the char in 2 bytes and write them into the file.

Parameters:
file - a file to read in.
value - a char to be writte into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeInt

public void writeInt(java.io.RandomAccessFile file,
                     int value)
              throws java.io.IOException
Convert the int in 4 bytes and write them into the file.

Parameters:
file - a file to read in.
value - an int to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeFloat

public void writeFloat(java.io.RandomAccessFile file,
                       float value)
                throws java.io.IOException
Convert the float in 4 bytes and write them into the file.

Parameters:
file - a file to read in.
value - a float to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeLong

public void writeLong(java.io.RandomAccessFile file,
                      long value)
               throws java.io.IOException
Convert the long in 8 bytes and write them into the file.

Parameters:
file - a file to read in.
value - a long to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeDouble

public void writeDouble(java.io.RandomAccessFile file,
                        double value)
                 throws java.io.IOException
Convert the double in 8 bytes and write them into the file.

Parameters:
file - a file to read in.
value - a double to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeByteArray

public void writeByteArray(java.io.RandomAccessFile file,
                           byte[] datas)
                    throws java.io.IOException
Write an entire byte[] into the file.
This is equivalent to the call writeByteArray(file, datase, 0, datas.length)

Parameters:
file - a file to read in.
datas - a byte[] to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeByteArray

public void writeByteArray(java.io.RandomAccessFile file,
                           byte[] datas,
                           int offset,
                           int length)
                    throws java.io.IOException
Write a part of a byte[] into the file.

Parameters:
file - a file to read in.
datas - a byte[] to write into the file.
offset - offset from the start of the byte[].
length - number of bytes to be written starting from the offset of the byte[].
Throws:
java.io.IOException - if an I/O exception occures.

writeByteBuffer

public int writeByteBuffer(java.io.RandomAccessFile file,
                           java.nio.ByteBuffer buffer)
                    throws java.io.IOException
Write an entire ByteBuffer into a file.

Parameters:
file - a file to read in.
buffer - a ByteBuffer to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.

writeByteBuffer

public int writeByteBuffer(java.io.RandomAccessFile file,
                           java.nio.ByteBuffer buffer,
                           int length)
                    throws java.io.IOException
Write a part of a ByteBuffer into a file.

Parameters:
file - a file to read in.
buffer - a ByteBuffer to be written into the file.
length - number of bytes to be written into the file.
Throws:
java.io.IOException - if an I/O exception occures.


NativeFmodEx Project - © Copyright 2005-2010 - Jérôme Jouvie (Jouvieje)
NativeFmodEx is an Open Source Project under GNU LGPL License
My sites : http://jerome.jouvie.free.fr/

(Documentation Copyright © Firelight Technologies - FMOD Ex - http://www.fmod.org)