Package com.linkedin.alpini.io
Class CompressOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.linkedin.alpini.io.CompressOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public final class CompressOutputStream extends java.io.FilterOutputStreamBackupOutputStream encapsulates an GZip compressor and provides methods to allow other threads to wait upon the completion of the file. However, when an exception occurs, the OutputStream is closed and the GZip compressor is not flushed, which should cut off the trailing footer leaving an invalid gzipped file.
-
-
Constructor Summary
Constructors Constructor Description CompressOutputStream(int compressionLevel, java.util.concurrent.ExecutorService executor, int numThreads, java.io.OutputStream out)Creates a compressed backup output stream built on top of the specified underlying output stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait()booleanawait(long timeout, java.util.concurrent.TimeUnit unit)voidclose()Closes this output stream and releases any system resources associated with the stream.voidflush()Flushes this output stream and forces any buffered output bytes to be written out to the stream.java.io.IOExceptionsetException(java.io.IOException cause)voidwrite(byte[] b)Writesb.lengthbytes to this output stream.voidwrite(byte[] b, int off, int len)Writeslenbytes from the specifiedbytearray starting at offsetoffto this output stream.voidwrite(int b)Writes the specifiedbyteto this output stream.
-
-
-
Constructor Detail
-
CompressOutputStream
public CompressOutputStream(int compressionLevel, java.util.concurrent.ExecutorService executor, int numThreads, @Nonnull @WillCloseWhenClosed java.io.OutputStream out) throws java.io.IOExceptionCreates a compressed backup output stream built on top of the specified underlying output stream.- Parameters:
compressionLevel- the compression level requested.executor- Thread pool for the parallel compressor.numThreads- requested compression parallelism.out- the underlying output stream to be assigned to the field this.out for later use, ornullif this instance is to be created without an underlying stream.- Throws:
java.io.IOException
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOExceptionWrites the specifiedbyteto this output stream.- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
b- thebyte.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(@Nonnull byte[] b) throws java.io.IOExceptionWritesb.lengthbytes to this output stream.- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
b- the data to be written.- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(@Nonnull byte[] b, int off, int len) throws java.io.IOExceptionWriteslenbytes from the specifiedbytearray starting at offsetoffto this output stream.- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
b- the data.off- the start offset in the data.len- the number of bytes to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
flush
public void flush() throws java.io.IOExceptionFlushes this output stream and forces any buffered output bytes to be written out to the stream. Theflushmethod ofFilterOutputStreamcalls theflushmethod of its underlying output stream.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterOutputStream- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
FilterOutputStream.out
-
await
public void await() throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
await
public boolean await(long timeout, @Nonnull java.util.concurrent.TimeUnit unit) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
close
public void close() throws java.io.IOExceptionCloses this output stream and releases any system resources associated with the stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException- if an I/O error occurs.
-
setException
public java.io.IOException setException(@Nonnull java.io.IOException cause)
-
-