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

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.tffenterprises.music.tag.id3v2.io.UnsynchronizedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class UnsynchronizedOutputStream
extends java.io.FilterOutputStream

A filter-type output stream that will de-unsynchronize data on the fly. MPEG's audio 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/27 16:44:48 $
Author:
Guillaume Lessard

Field Summary
private  boolean hasUnsynchronized
          A boolean that represents whether or not a single null byte has been written to the output stream as an unsynchronizing action.
private  boolean lastByteFull
          A boolean that represents whether or not the latest byte written to the output stream was equal to 0xff.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
UnsynchronizedOutputStream(java.io.OutputStream out)
          The constructor takes as a parameter the OutputStream instance to which the Unsynchronized bytes shall be written.
 
Method Summary
 void flush()
          Flushes this output stream and forces any buffered output to be written out to the stream.
 boolean hasUnsynchronized()
          Returns whether or not a single null byte has been written to the output stream as an unsynchronizing action.
 void write(byte[] b, int off, int len)
          Writes len bytes to the output stream, starting to read them from offset off in the given byte array.
 void write(int b)
          Writes the specified byte to this output stream, unsynchronizing the output as necessary.
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastByteFull

private boolean lastByteFull
A boolean that represents whether or not the latest byte written to the output stream was equal to 0xff. If so, the next byte should be preceded by a null if it is null or has the bits 0xe0 turned on.


hasUnsynchronized

private boolean hasUnsynchronized
A boolean that represents whether or not a single null byte has been written to the output stream as an unsynchronizing action.

Constructor Detail

UnsynchronizedOutputStream

public UnsynchronizedOutputStream(java.io.OutputStream out)
The constructor takes as a parameter the OutputStream instance to which the Unsynchronized bytes shall be written.

Parameters:
out - the OutputStream instance to which the unsynchronized bytes shall be written.
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream, unsynchronizing the output as necessary.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the byte to be written out.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes to the output stream, starting to read them from offset off in the given byte array.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write out of the data.
Throws:
java.io.IOException - if an I/O error occurs.

flush

public void flush()
           throws java.io.IOException
Flushes this output stream and forces any buffered output to be written out to the stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.FilterOutputStream
Throws:
java.io.IOException - if an I/O error occurs.

hasUnsynchronized

public boolean hasUnsynchronized()
Returns whether or not a single null byte has been written to the output stream as an unsynchronizing action.

Returns:
whether an unsynchronizing action has been made.