DeflaterOutputStream.java, [...]: Reformatted.
2004-07-09 Michael Koch <konqueror@gmx.de> * java/util/zip/DeflaterOutputStream.java, java/util/zip/GZIPInputStream.java, java/util/zip/GZIPOutputStream.java, java/util/zip/InflaterInputStream.java: Reformatted. Added javadocs. Reordered all stuff. Renamed variables to be more clear. From-SVN: r84380
This commit is contained in:
parent
fbc40a17c9
commit
d642571f32
5 changed files with 208 additions and 131 deletions
|
@ -60,18 +60,23 @@ import java.io.IOException;
|
|||
*/
|
||||
public class DeflaterOutputStream extends FilterOutputStream
|
||||
{
|
||||
public void close () throws IOException
|
||||
{
|
||||
finish ();
|
||||
out.close();
|
||||
}
|
||||
/**
|
||||
* This buffer is used temporarily to retrieve the bytes from the
|
||||
* deflater and write them to the underlying output stream.
|
||||
*/
|
||||
protected byte[] buf;
|
||||
|
||||
/**
|
||||
* The deflater which is used to deflate the stream.
|
||||
*/
|
||||
protected Deflater def;
|
||||
|
||||
/**
|
||||
* Deflates everything in the def's input buffers. This will call
|
||||
* <code>def.deflate()</code> until all bytes from the input buffers
|
||||
* are processed.
|
||||
*/
|
||||
protected void deflate () throws IOException
|
||||
protected void deflate() throws IOException
|
||||
{
|
||||
do
|
||||
{
|
||||
|
@ -87,9 +92,9 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
* default buffer size.
|
||||
* @param out the output stream where deflated output should be written.
|
||||
*/
|
||||
public DeflaterOutputStream (OutputStream out)
|
||||
public DeflaterOutputStream(OutputStream out)
|
||||
{
|
||||
this (out, new Deflater (), 512);
|
||||
this(out, new Deflater(), 512);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,9 +103,9 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
* @param out the output stream where deflated output should be written.
|
||||
* @param defl the underlying deflater.
|
||||
*/
|
||||
public DeflaterOutputStream (OutputStream out, Deflater defl)
|
||||
public DeflaterOutputStream(OutputStream out, Deflater defl)
|
||||
{
|
||||
this (out, defl, 512);
|
||||
this(out, defl, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +118,7 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
*/
|
||||
public DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize)
|
||||
{
|
||||
super (out);
|
||||
super(out);
|
||||
if (bufsize <= 0)
|
||||
throw new IllegalArgumentException("bufsize <= 0");
|
||||
buf = new byte[bufsize];
|
||||
|
@ -125,11 +130,11 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
* was the only way to ensure that all bytes are flushed in Sun's
|
||||
* JDK.
|
||||
*/
|
||||
public void finish () throws IOException
|
||||
public void finish() throws IOException
|
||||
{
|
||||
inbufWrite();
|
||||
def.finish();
|
||||
while (! def.finished ())
|
||||
while (! def.finished())
|
||||
{
|
||||
int len = def.deflate(buf, 0, buf.length);
|
||||
if (len > 0)
|
||||
|
@ -137,29 +142,48 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
}
|
||||
}
|
||||
|
||||
public void write (int bval) throws IOException
|
||||
/**
|
||||
* Calls finish() and closes the stream.
|
||||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
finish();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single byte to the compressed output stream.
|
||||
* @param bval the byte value.
|
||||
*/
|
||||
public void write(int bval) throws IOException
|
||||
{
|
||||
if (inbuf == null)
|
||||
inbuf = new byte[128];
|
||||
else if (inbufLength == inbuf.length)
|
||||
inbufWrite ();
|
||||
inbufWrite();
|
||||
inbuf[inbufLength++] = (byte) bval;
|
||||
}
|
||||
|
||||
public void write (byte[] buf, int off, int len) throws IOException
|
||||
/**
|
||||
* Writes a len bytes from an array to the compressed stream.
|
||||
* @param buf the byte array.
|
||||
* @param off the offset into the byte array where to start.
|
||||
* @param len the number of bytes to write.
|
||||
*/
|
||||
public void write(byte[] buf, int off, int len) throws IOException
|
||||
{
|
||||
inbufWrite ();
|
||||
def.setInput (buf, off, len);
|
||||
deflate ();
|
||||
inbufWrite();
|
||||
def.setInput(buf, off, len);
|
||||
deflate();
|
||||
}
|
||||
|
||||
private void inbufWrite () throws IOException
|
||||
private void inbufWrite() throws IOException
|
||||
{
|
||||
if (inbufLength > 0)
|
||||
{
|
||||
int size = inbufLength;
|
||||
inbufLength = 0;
|
||||
write (inbuf, 0, size);
|
||||
write(inbuf, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,10 +191,4 @@ public class DeflaterOutputStream extends FilterOutputStream
|
|||
private byte[] inbuf;
|
||||
// Used length of inbuf.
|
||||
private int inbufLength;
|
||||
|
||||
// The retrieval buffer.
|
||||
protected byte[] buf;
|
||||
|
||||
// Deflater used to compress data.
|
||||
protected Deflater def;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue