Class Overview
The GZIPOutputStream
class is used to write data to a stream in the
GZIP storage format.
Example
Using GZIPOutputStream
is a little easier than ZipOutputStream
because GZIP is only for compression, and is not a container for multiple files.
This code creates a GZIP stream, similar to the gzip(1)
utility.
OutputStream os = ...
byte[] bytes = ...
GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(os));
try {
zos.write(bytes);
} finally {
zos.close();
}
Summary
Fields |
protected
CRC32 |
crc |
The checksum algorithm used when treating uncompressed data. |
Public Methods |
void
|
finish()
Indicates to the stream that all data has been written out, and any GZIP
terminal data can now be written.
|
void
|
write(byte[] buffer, int off, int nbytes)
Write up to nbytes of data from the given buffer, starting at offset off,
to the underlying stream in GZIP format.
|
[Expand]
Inherited Methods |
From class
java.util.zip.DeflaterOutputStream
void
|
close()
Writes any unwritten compressed data to the underlying stream, the closes
all underlying streams.
|
void
|
deflate()
Compress the data in the input buffer and write it to the underlying
stream.
|
void
|
finish()
Writes any unwritten data to the underlying stream.
|
void
|
flush()
Flushes the underlying stream.
|
void
|
write(byte[] buffer, int offset, int byteCount)
Compresses byteCount bytes of data from buf starting at
offset and writes it to the underlying stream.
|
void
|
write(int i)
Writes one byte to the target stream.
|
|
From class
java.io.FilterOutputStream
void
|
close()
Closes this stream.
|
void
|
flush()
Ensures that all pending data is sent out to the target stream.
|
void
|
write(byte[] buffer, int offset, int length)
Writes count bytes from the byte array buffer starting at
offset to the target stream.
|
void
|
write(int oneByte)
Writes one byte to the target stream.
|
|
From class
java.io.OutputStream
void
|
close()
Closes this stream.
|
void
|
flush()
Flushes this stream.
|
void
|
write(byte[] buffer, int offset, int count)
Writes count bytes from the byte array buffer starting at
position offset to this stream.
|
void
|
write(byte[] buffer)
Equivalent to write(buffer, 0, buffer.length) .
|
abstract
void
|
write(int oneByte)
Writes a single byte to this stream.
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes the object and release any system resources it holds.
|
|
From interface
java.io.Flushable
abstract
void
|
flush()
Flushes the object by writing out any buffered data to the underlying
output.
|
|
Fields
protected
CRC32
crc
The checksum algorithm used when treating uncompressed data.
Public Constructors
public
GZIPOutputStream
(OutputStream os)
Construct a new GZIPOutputStream
to write data in GZIP format to
the underlying stream.
Parameters
os
| the OutputStream to write data to. |
public
GZIPOutputStream
(OutputStream os, int size)
Construct a new GZIPOutputStream
to write data in GZIP format to
the underlying stream. Set the internal compression buffer to size
size
.
Parameters
os
| the OutputStream to write to. |
size
| the internal buffer size. |
Public Methods
public
void
finish
()
Indicates to the stream that all data has been written out, and any GZIP
terminal data can now be written.
public
void
write
(byte[] buffer, int off, int nbytes)
Write up to nbytes of data from the given buffer, starting at offset off,
to the underlying stream in GZIP format.
Parameters
buffer
| the buffer to write. |
off
| the index of the first byte in buffer to write. |
nbytes
| the number of bytes in buffer to write. |