hu.netmind.ogg
Class OggOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by hu.netmind.ogg.OggOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class OggOutputStream
extends java.io.OutputStream

This class is the starting point for creating an ogg bitstream. This class handles all features of the Ogg bitstream (as of RFC3533), including multiplexing (grouping, chaining).
Grouping:Grouping is a form of multiplexing several logical streams (eg. 1 audio, 1 video) into one stream. The Ogg format itself does not specify exactly how data from these streams should be written (in which order), so this class simply writes data out, when it arrives on the logical input streams. To obtain several logical input streams (eg. 1 for the video stream, 1 for the audio stream), call createLogicalOutputStream which will return a stream to write.
Chaning:Chaning several logic streams means to concatenate two ogg streams together. The Ogg specification says, that you must create all logical output streams, before any data is to be written to any of the created logical streams (except the header data, which is the first written packet.) (In short: you must call the createLogicalOutputStream() prior to any subsequent writePacket()). But, if you eventually close all logical streams (these don't have to occur in any specific order), then you may call createLogicalOutputStream() again (any number of times), if you whish to "chain" new logical streams to this one.
The output of this stream may not be written on each call to write() on the logical streams, because of internal buffering/paging, but all data is guaranteed to be written on close().
This class is thread-safe, meaning that the separate logical streams may be written to concurrently, and this class may be used by more than one thread (to create logical streams, and to get information).


Constructor Summary
OggOutputStream(java.io.OutputStream output)
          The ogg bitstream will be written in the given output stream.
 
Method Summary
 void close()
          Close this Ogg stream, write any data that is pending into the stream, then releas all resources.
 LogicalOutputStream createLogicalOutputStream()
          Create a logical bitstream to be written to this Ogg stream.
A logical stream is a stream associated with the output of a single codec/source (eg.
 void flush()
          Proxy call to output.
 boolean isClean()
          Return, whether the call to createLogicalOutputStream() will success.
 void waitForClose()
          Wait for all logical streams to finish.
 void write(byte[] b)
          Proxy call to output, this method should not be called, as it writes directly into the ogg stream.
 void write(byte[] b, int offset, int length)
          Proxy call to output, this method should not be called, as it writes directly into the ogg stream.
 void write(int b)
          Proxy call to output, this method should not be called, as it writes directly into the ogg stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OggOutputStream

public OggOutputStream(java.io.OutputStream output)
The ogg bitstream will be written in the given output stream.

Parameters:
output - The output stream the ogg is to be written to.
Method Detail

isClean

public boolean isClean()
Return, whether the call to createLogicalOutputStream() will success. Note, however, that in a multi-threaded environment this call may return true, but directly after it the real call may fail regardless (a concurrent thread may have already written data by then).

Returns:
True, if the next call to createLogicalOutputStream() will succseed or not. That is, is there an open logical stream, how already sent data too.

createLogicalOutputStream

public LogicalOutputStream createLogicalOutputStream()
                                              throws InvalidStateException
Create a logical bitstream to be written to this Ogg stream.
A logical stream is a stream associated with the output of a single codec/source (eg. the audio codec).

Returns:
A logical output stream object.
Throws:
InvalidStateException - If there is already data written to the Ogg stream, and there is at least one logical stream still open.

close

public void close()
           throws java.io.IOException
Close this Ogg stream, write any data that is pending into the stream, then releas all resources. Subsequent calls to any methods after calling close() result in undefined results.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - If the output could not be written.

waitForClose

public void waitForClose()
Wait for all logical streams to finish. This method blocks until all current logical streams finish/close or this ogg stream closes. If currently there are no logical streams, method returns.
Note: This method is not thread-safe, only call from one thread.


flush

public void flush()
           throws java.io.IOException
Proxy call to output.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Proxy call to output, this method should not be called, as it writes directly into the ogg stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Proxy call to output, this method should not be called, as it writes directly into the ogg stream.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Proxy call to output, this method should not be called, as it writes directly into the ogg stream.

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException