org.at4j.comp.bzip2
Class BZip2OutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.at4j.comp.bzip2.BZip2OutputStream
All Implemented Interfaces:
Closeable, Flushable

public class BZip2OutputStream
extends OutputStream

This is an OutputStream for bzip2 compressing data.

For more information on the inner workings of bzip2, see the Wikipedia article on bzip2.

This stream is not safe for concurrent access by several writing threads. A client must provide external synchronization to use this from several threads.

Since:
1.1
Author:
Karl Gustafsson
See Also:
BZip2OutputStreamSettings, BZip2InputStream

Constructor Summary
BZip2OutputStream(OutputStream wrapped)
          Create a new bzip2 compressing output stream with default settings.
BZip2OutputStream(OutputStream wrapped, BZip2OutputStreamSettings settings)
          Create a new bzip2 compressing output stream.
 
Method Summary
 void close()
           
static BZip2EncoderExecutorService createExecutorService()
          Create a BZip2EncoderExecutorService that can be shared between several BZip2OutputStream:s to spread the bzip2 encoding work over several threads.
static BZip2EncoderExecutorService createExecutorService(int noThreads)
          Create a BZip2EncoderExecutorService that can be shared between several BZip2OutputStream:s to spread the bzip2 encoding work over several threads.
 boolean equals(Object o)
           
protected  void finalize()
          Close the stream if the client has been sloppy about it.
 int hashCode()
           
 void write(byte[] data)
           
 void write(byte[] data, int offset, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BZip2OutputStream

public BZip2OutputStream(OutputStream wrapped)
                  throws IOException
Create a new bzip2 compressing output stream with default settings.

Parameters:
wrapped - Compressed data is written to this stream.
Throws:
IOException - On errors writing the file header.
See Also:
BZip2OutputStream(OutputStream, BZip2OutputStreamSettings)

BZip2OutputStream

public BZip2OutputStream(OutputStream wrapped,
                         BZip2OutputStreamSettings settings)
                  throws IOException
Create a new bzip2 compressing output stream.

Parameters:
wrapped - Compressed data is written to this stream.
settings - Compression settings.
Throws:
IOException - On errors writing the file header.
See Also:
BZip2OutputStream(OutputStream)
Method Detail

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] data)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] data,
                  int offset,
                  int len)
           throws IOException,
                  IndexOutOfBoundsException
Overrides:
write in class OutputStream
Throws:
IOException
IndexOutOfBoundsException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

finalize

protected void finalize()
                 throws Throwable
Close the stream if the client has been sloppy about it.

Overrides:
finalize in class Object
Throws:
Throwable

createExecutorService

public static BZip2EncoderExecutorService createExecutorService(int noThreads)
Create a BZip2EncoderExecutorService that can be shared between several BZip2OutputStream:s to spread the bzip2 encoding work over several threads. The created executor service can be passed to the BZip2OutputStream constructor in a BZip2OutputStreamSettings object.

Parameters:
noThreads - The number of threads available to the executor.
Returns:
The executor service.

createExecutorService

public static BZip2EncoderExecutorService createExecutorService()
Create a BZip2EncoderExecutorService that can be shared between several BZip2OutputStream:s to spread the bzip2 encoding work over several threads. The created executor service can be passed to the BZip2OutputStream constructor in a BZip2OutputStreamSettings object.

The created executor will have as many threads available to it as there are CPU:s available to the JVM.

Returns:
The executor service.