Maven module :un.storage : media-mpeg4 :
Class : un.storage.media.mp4.MP4InputStream
Extends/Implements : -
Subclasses : -

author  Alexander Simm


Variables : MASK8, MASK16
Functions : MP4InputStream, MP4InputStream, read, read, readBytes, readBytes, readString, readUTFString, readUTFString, readTerminated, readFixedPoint, skipBytes, getOffset, seek, hasRandomAccess, hasLeft, close


public int MASK8

public int MASK16



Constructs an MP4InputStream that reads from an
InputStream. It will have no random access, thus seeking
will not be possible.

@param in an InputStream to read from
void MP4InputStream (ByteInputStream in)


Constructs an MP4InputStream that reads from a
RandomAccessFile. It will have random access and seeking
will be possible.

@param in a RandomAccessFile to read from
void MP4InputStream (SeekableByteBuffer fin)


Reads the next byte of data from the input. The value byte is returned as
an int in the range 0 to 255. If no byte is available because the end of
the stream has been reached, an EOFException is thrown. This method
blocks until input data is available, the end of the stream is detected,
or an I/O error occurs.
return  the next byte of data
throws  IOException If the end of the stream is detected or any I/O error occurs.
public int read ()


Reads len bytes of data from the input into the array
b. If len is zero, then no bytes are read.

This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.

If the stream ends before len bytes could be read an
EOFException is thrown.

@param b the buffer into which the data is read.
@param off the start offset in array b at which the data is written.
@param len the number of bytes to read.
@throws IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public void read (byte[] b, int off, int len)


Reads up to eight bytes as a long value. This method blocks until all
bytes could be read, the end of the stream is detected, or an I/O error
occurs.

@param n the number of bytes to read >0 and <=8
@return the read bytes as a long value
@throws IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
@throws IndexOutOfBoundsException if n is not in the range
[1...8] inclusive.
public long readBytes (int n)


Reads data from the input stream and stores them into the buffer array b.
This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.
If the length of b is zero, then no bytes are read.
param  b the buffer into which the data is read.
throws  IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public void readBytes (byte[] b)


Reads n bytes from the input as a String. The bytes are
directly converted into characters. If not enough bytes could be read, an
EOFException is thrown.
This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.
param  n the length of the String.
return  the String, that was read
throws  IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public String readString (int n)


Reads a null-terminated UTF-encoded String from the input. The maximum
number of bytes that can be read before the null must appear must be
specified.
Although the method is preferred for unicode, the encoding can be any
charset name, that is supported by the system.
This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.
param  max the maximum number of bytes to read, before the null-terminator
must appear.
param  encoding the charset used to encode the String
return  the decoded String
throws  IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public String readUTFString (int max, Charset encoding)


Reads a null-terminated UTF-encoded String from the input. The maximum
number of bytes that can be read before the null must appear must be
specified.
The encoding is detected automatically, it may be UTF-8 or UTF-16
(determined by a byte order mask at the beginning).

This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.

@param max the maximum number of bytes to read, before the null-terminator
must appear.
@return the decoded String
@throws IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public String readUTFString (int max)


Reads a byte array from the input that is terminated by a specific byte
(the 'terminator'). The maximum number of bytes that can be read before
the terminator must appear must be specified.

The terminator will not be included in the returned array.

This method blocks until all bytes could be read, the end of the stream
is detected, or an I/O error occurs.

@param max the maximum number of bytes to read, before the terminator
must appear.
@param terminator the byte that indicates the end of the array
@return the buffer into which the data is read.
@throws IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public byte[] readTerminated (int max, int terminator)


Reads a fixed point number from the input. The number is read as a
m.n value, that results from deviding an integer by
2n.

@param m the number of bits before the point
@param n the number of bits after the point
@return a floating point number with the same value
@throws IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
@throws IllegalArgumentException if the total number of bits (m+n) is not
a multiple of eight
public double readFixedPoint (int m, int n)


Skips n bytes in the input. This method blocks until all
bytes could be skipped, the end of the stream is detected, or an I/O
error occurs.
param  n the number of bytes to skip
throws  IOException If the end of the stream is detected, the input
stream has been closed, or if some other I/O error occurs.
public void skipBytes (long n)


Returns the current offset in the stream.
return  the current offset
throws  IOException if an I/O error occurs (only when using a RandomAccessFile)
public long getOffset ()


Seeks to a specific offset in the stream. This is only possible when
using a RandomAccessFile. If an InputStream is used, this method throws
an IOException.
param  pos the offset position, measured in bytes from the beginning of the
stream
throws  IOException if an InputStream is used, pos is less than 0 or an
I/O error occurs
public void seek (long pos)


Indicates, if random access is available. That is, if this
MP4InputStream was constructed with a RandomAccessFile. If
this method returns false, seeking is not possible.

@return true if random access is available
public boolean hasRandomAccess ()


Indicates, if the input has some data left.
return  true if there is at least one byte left
throws  IOException if an I/O error occurs
public boolean hasLeft ()


Closes the input and releases any system resources associated with it.
Once the stream has been closed, further reading or skipping will throw
an IOException. Closing a previously closed stream has no effect.
throws  IOException if an I/O error occurs
void close ()