com.jme3.scene.plugins.blender.file
Class BlenderInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.jme3.scene.plugins.blender.file.BlenderInputStream
All Implemented Interfaces:
java.io.Closeable

public class BlenderInputStream
extends java.io.InputStream

An input stream with random access to data.


Field Summary
protected  byte[] cachedBuffer
          The buffer we store the read data to.
protected  java.io.InputStream inputStream
          The input stream we read the data from.
protected  int position
          The current position of the read cursor.
protected  int size
          The total size of the stored data.
 
Constructor Summary
BlenderInputStream(java.io.InputStream inputStream, AssetManager assetManager)
          Constructor.
 
Method Summary
 void alignPosition(int bytesAmount)
          This method aligns cursor position forward to a given amount of bytes.
 void close()
           
 AssetManager getAssetManager()
          This method returns the application's asset manager.
 int getPointerSize()
          This method returns the size of the pointer.
 int getPosition()
          This method returns the position of the read cursor.
 java.lang.String getVersionNumber()
          This method returns the blender version number where the file was created.
 int read()
           
 int readByte()
          This method reads 1 byte from the stream.
 double readDouble()
          This method reads 8-byte floating point number (double) from the stream.
 float readFloat()
          This method reads 4-byte floating point number (float) from the stream.
 int readInt()
          This method reads 4-byte number from the stream.
 long readLong()
          This method reads 8-byte number from the stream.
 long readPointer()
          This method reads the pointer value.
 int readShort()
          This method reads 2-byte number from the stream.
 java.lang.String readString()
          This method reads the string.
 void setPosition(int position)
          This method sets the current position of the read cursor.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedBuffer

protected byte[] cachedBuffer
The buffer we store the read data to.


size

protected int size
The total size of the stored data.


position

protected int position
The current position of the read cursor.


inputStream

protected java.io.InputStream inputStream
The input stream we read the data from.

Constructor Detail

BlenderInputStream

public BlenderInputStream(java.io.InputStream inputStream,
                          AssetManager assetManager)
                   throws BlenderFileException
Constructor. The input stream is stored and used to read data.

Parameters:
inputStream - the stream we read data from
assetManager - the application's asset manager
Throws:
BlenderFileException - this exception is thrown if the file header has some invalid data
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

readByte

public int readByte()
This method reads 1 byte from the stream. It works just in the way the read method does. It just not throw an exception because at this moment the whole file is loaded into buffer, so no need for IOException to be thrown.

Returns:
a byte from the stream (1 bytes read)

readShort

public int readShort()
This method reads 2-byte number from the stream.

Returns:
a number from the stream (2 bytes read)

readInt

public int readInt()
This method reads 4-byte number from the stream.

Returns:
a number from the stream (4 bytes read)

readFloat

public float readFloat()
This method reads 4-byte floating point number (float) from the stream.

Returns:
a number from the stream (4 bytes read)

readLong

public long readLong()
This method reads 8-byte number from the stream.

Returns:
a number from the stream (8 bytes read)

readDouble

public double readDouble()
This method reads 8-byte floating point number (double) from the stream.

Returns:
a number from the stream (8 bytes read)

readPointer

public long readPointer()
This method reads the pointer value. Depending on the pointer size defined in the header, the stream reads either 4 or 8 bytes of data.

Returns:
the pointer value

readString

public java.lang.String readString()
This method reads the string. It assumes the string is terminated with zero in the stream.

Returns:
the string read from the stream

setPosition

public void setPosition(int position)
This method sets the current position of the read cursor.

Parameters:
position - the position of the read cursor

getPosition

public int getPosition()
This method returns the position of the read cursor.

Returns:
the position of the read cursor

getVersionNumber

public java.lang.String getVersionNumber()
This method returns the blender version number where the file was created.

Returns:
blender version number

getPointerSize

public int getPointerSize()
This method returns the size of the pointer.

Returns:
the size of the pointer

getAssetManager

public AssetManager getAssetManager()
This method returns the application's asset manager.

Returns:
the application's asset manager

alignPosition

public void alignPosition(int bytesAmount)
This method aligns cursor position forward to a given amount of bytes.

Parameters:
bytesAmount - the byte amount to which we aligh the cursor

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException