com.tffenterprises.music.tag.id3v2.io
Class UnsynchronizedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.tffenterprises.music.tag.id3v2.io.UnsynchronizedInputStream
All Implemented Interfaces:
java.io.Closeable

public class UnsynchronizedInputStream
extends java.io.FilterInputStream

A filter-type input stream that will de-unsynchronize data on the fly. The MPEG algorithm detects a starting point by detecting that two bytes (represented by the variable theShort) such that the expression ((theShort & 0xffe0) == 0xffe0) is true. The unsynchronization scheme is a reversible modification of the data in such a way that the MPEG algorithm will not find a valid start marker in the body of an ID3v2 tag. To unsynchronize a given output stream, construct an UnsynchronizedOutputStream using the output stream you want to unsynchronize as its argument. To de-unsynchronize a given input stream, construct an UnsynchronizedInputStream using the input stream you want to de-unsynchronize as its argument.

Version:
1.0d1 $Date: 2002/09/30 16:35:49 $
Author:
Guillaume Lessard

Field Summary
private  boolean skipIfNull
          A boolean representing whether or not the last byte read from the the input stream was equal to 0xff.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
UnsynchronizedInputStream(java.io.InputStream in)
          The constructor takes as a parameter the InputStream instance from which the Unsynchronized bytes shall be read.
 
Method Summary
 int read()
          Reads a byte from this input stream, de-unsynchronizing the input as necessary.
 int read(byte[] b, int off, int len)
          Reads len bytes from the input stream, starting to write them at offset off in the given byte array and de-unsynchronizing as necessary.
 long skip(long n)
          Skips over and discards n bytes of data from the input stream.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

skipIfNull

private boolean skipIfNull
A boolean representing whether or not the last byte read from the the input stream was equal to 0xff. If so, the next byte should be skipped if it is a null byte.

Constructor Detail

UnsynchronizedInputStream

public UnsynchronizedInputStream(java.io.InputStream in)
The constructor takes as a parameter the InputStream instance from which the Unsynchronized bytes shall be read.

Parameters:
in - the InputStream instance from which the unsynchronized bytes shall be read.
Method Detail

read

public int read()
         throws java.io.IOException
Reads a byte from this input stream, de-unsynchronizing the input as necessary.

Overrides:
read in class java.io.FilterInputStream
Returns:
the next (unsigned) byte of data, or -1 if the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads len bytes from the input stream, starting to write them at offset off in the given byte array and de-unsynchronizing as necessary.

Overrides:
read in class java.io.FilterInputStream
Parameters:
b - the buffer to which data will be written.
off - the start offset at which the data will be written.
len - the number of bytes of data that should be read.
Returns:
the number of bytes that were read, or -1 if the end of the stream was reached.
Throws:
java.io.IOException - if an I/O error occurs.

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from the input stream. The data that is discarded is not the raw unsynchronized data, but the de-unsynchronized data. This is the desirable behaviour for versions 2.0 through 3.x of ID3v2.

This implementation attempts to skip exactly the number of bytes requested, and will block until having skipped the correct number or reaching the end of file. The actual number of bytes skipped is returned and may be smaller than n

Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - the number of bytes to skip in the input stream.
Returns:
the number of bytes that were skipped.
Throws:
java.io.IOException - if an I/O error occurs