dguitar.codecs.guitarPro
Class GPInputStream

java.lang.Object
  extended bydguitar.codecs.guitarPro.GPInputStream
All Implemented Interfaces:
Codec, CodecInputStream
Direct Known Subclasses:
GP1InputStream, GP2InputStream, GP3InputStream, GP4InputStream

public class GPInputStream
extends java.lang.Object
implements CodecInputStream

This class is the base class to read Guitar Pro files. It is extended by GP3InputStream and GP4InputStream that read respectively files of version 3 and 4.

Author:
Mauricio Gracia Gutiérrez

Field Summary
protected  java.lang.String __fileName
          The filename (equals to "" if not available).
protected  java.lang.String __version
          The file version.
private  CodecFileFilter _codecFileFilter
          The file filter.
private  java.io.InputStream _in
          The InputStream from which the data is read.
private  int _offset
          The offset where we got so far in the file.
 
Constructor Summary
  GPInputStream(java.io.File f)
          Creates a new GPInputStream using the file f.
protected GPInputStream(GPInputStream gpIn)
          Creates a new GPInputStream by cloning an existing GPInputStream.
  GPInputStream(java.io.InputStream in)
          Creates a new GPInputStream from an existing stream.
  GPInputStream(java.lang.String fileName)
          Creates a new GPInputStream using the file of name fileName.
private GPInputStream(java.lang.String fileName, java.io.InputStream in)
          Creates a new GPInputStream from an existing stream.
 
Method Summary
protected  void assertBytesEqualTo(int n, int v)
          Asserts that n consecutive bytes are equal to a certain value.
 void close()
          Closes the stream.
protected  void dumpBytes(int n)
          Reads n bytes and prints them to the screen
protected  void dumpInts(int n)
          Reads n ints and prints them to the screen
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b)
          Reads some number of bytes from the input stream and stores them into the buffer array b.
protected  boolean readBoolean()
          Reads a boolean from the stream.
protected  byte readByte()
          Reads a byte from the stream.
protected  double readDouble()
          Reads a double from the stream.
protected  float readFloat()
          Reads an float from the stream.
protected  int readInt()
          Reads an LSB integer from the stream.
protected  long readLong()
          Reads a long integer from the stream.
 java.lang.Object readObject()
          Read the input stream on to a single object !!
private  GPSong readPiece()
          Reads a piece from the stream.
protected  java.lang.String readStringByte(int expectedLength)
          Reads a string from the stream ; its length is given by a byte.
protected  java.lang.String readStringByteMaxLengthPlusOne()
          Reads a string from the stream ; its maximum length is obtained by substracting 1 to a byte read, while its real length is obtained by reading the next byte.
protected  java.lang.String readStringInteger()
          Reads a string from the stream ; its length is given by an integer.
protected  java.lang.String readStringIntegerPlusOne()
          Reads a string from the stream ; its length is obtained by substracting 1 to an integer read.
protected  int readUnsignedByte()
          Reads an unsigned byte from the stream.
 long skip(long n)
          Skips over and discards n bytes of data from this input stream.
 boolean supportedExtension(java.lang.String extension)
          Returns if the extension is supported by this codec
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__fileName

protected java.lang.String __fileName
The filename (equals to "" if not available).


__version

protected java.lang.String __version
The file version.


_codecFileFilter

private CodecFileFilter _codecFileFilter
The file filter.


_in

private java.io.InputStream _in
The InputStream from which the data is read.


_offset

private int _offset
The offset where we got so far in the file.

Constructor Detail

GPInputStream

public GPInputStream(java.lang.String fileName)
              throws java.io.FileNotFoundException
Creates a new GPInputStream using the file of name fileName.

Parameters:
fileName - the given file's name.
Throws:
java.io.FileNotFoundException

GPInputStream

public GPInputStream(java.io.File f)
              throws java.io.FileNotFoundException
Creates a new GPInputStream using the file f.

Parameters:
f - the given file.
Throws:
java.io.FileNotFoundException

GPInputStream

public GPInputStream(java.io.InputStream in)
Creates a new GPInputStream from an existing stream.

Parameters:
in - the original stream.

GPInputStream

private GPInputStream(java.lang.String fileName,
                      java.io.InputStream in)
Creates a new GPInputStream from an existing stream.

Parameters:
fileName - the name of the file the stream has been opened from.
in - the original stream.

GPInputStream

protected GPInputStream(GPInputStream gpIn)
Creates a new GPInputStream by cloning an existing GPInputStream. This is very useful when the method readPiece is called. Indeed, it starts by reading the version of Guitar Pro the file was encoded with, and then starts the decoding accordingly ; this implies that it may create a GP2InputStream, GP3InputStream, or GP4InputStream, while keeping the same state of the stream.

Parameters:
gpIn - the original GPInputStream.
Method Detail

close

public void close()
           throws java.io.IOException
Closes the stream.

Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Reads the next byte of data from the input stream.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer array b.

Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

readObject

public java.lang.Object readObject()
                            throws java.io.IOException,
                                   GPFormatException
Description copied from interface: CodecInputStream
Read the input stream on to a single object !! (is this good?)

Specified by:
readObject in interface CodecInputStream
Throws:
java.io.IOException
GPFormatException
See Also:
CodecInputStream.readObject()

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from this input stream.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException

supportedExtension

public boolean supportedExtension(java.lang.String extension)
Description copied from interface: Codec
Returns if the extension is supported by this codec

Specified by:
supportedExtension in interface Codec
Parameters:
extension - ".GP3" or ".TAB" or something else
Returns:
true if this codec know how to hadle that extension
See Also:
Codec.supportedExtension(java.lang.String)

assertBytesEqualTo

protected void assertBytesEqualTo(int n,
                                  int v)
                           throws java.io.IOException
Asserts that n consecutive bytes are equal to a certain value.

Parameters:
n - the number of bytes.
v - the value.
Throws:
java.io.IOException

dumpBytes

protected void dumpBytes(int n)
                  throws java.io.IOException
Reads n bytes and prints them to the screen

Parameters:
n - the number of bytes to read
Throws:
java.io.IOException

dumpInts

protected void dumpInts(int n)
                 throws java.io.IOException
Reads n ints and prints them to the screen

Parameters:
n - the number of ints to read
Throws:
java.io.IOException

readBoolean

protected boolean readBoolean()
                       throws java.io.IOException
Reads a boolean from the stream.

Returns:
the boolean read.
Throws:
java.io.IOException

readByte

protected byte readByte()
                 throws java.io.IOException
Reads a byte from the stream.

Returns:
the byte read.
Throws:
java.io.IOException

readDouble

protected double readDouble()
                     throws java.io.IOException
Reads a double from the stream.

Returns:
the double read.
Throws:
java.io.IOException

readFloat

protected float readFloat()
                   throws java.io.IOException
Reads an float from the stream.

Returns:
the float read.
Throws:
java.io.IOException

readInt

protected int readInt()
               throws java.io.IOException
Reads an LSB integer from the stream.

Returns:
the int read.
Throws:
java.io.IOException

readLong

protected long readLong()
                 throws java.io.IOException
Reads a long integer from the stream.

Returns:
the long read.
Throws:
java.io.IOException

readStringByte

protected java.lang.String readStringByte(int expectedLength)
                                   throws java.io.IOException
Reads a string from the stream ; its length is given by a byte.

Parameters:
expectedLength - if superior to 0, gives the maximum length we expect to find.
Returns:
the String read.
Throws:
java.io.IOException

readStringInteger

protected java.lang.String readStringInteger()
                                      throws java.io.IOException
Reads a string from the stream ; its length is given by an integer.

Returns:
the String read.
Throws:
java.io.IOException

readStringIntegerPlusOne

protected java.lang.String readStringIntegerPlusOne()
                                             throws java.io.IOException
Reads a string from the stream ; its length is obtained by substracting 1 to an integer read.

Returns:
the String read.
Throws:
java.io.IOException

readStringByteMaxLengthPlusOne

protected java.lang.String readStringByteMaxLengthPlusOne()
                                                   throws java.io.IOException
Reads a string from the stream ; its maximum length is obtained by substracting 1 to a byte read, while its real length is obtained by reading the next byte.

Returns:
the string read.
Throws:
java.io.IOException

readUnsignedByte

protected int readUnsignedByte()
                        throws java.io.IOException
Reads an unsigned byte from the stream.

Returns:
the unsigned byte (as an int) read.
Throws:
java.io.IOException

readPiece

private GPSong readPiece()
                  throws java.io.IOException,
                         GPFormatException
Reads a piece from the stream.

Returns:
the piece read as a GPSong.
Throws:
java.io.IOException
GPFormatException