java2.util2.zip2.DeflaterOutputStream: 97.22%

Overview

Search Parameters

EvoSuite Parameters

Old Parameters

Statistics

Test suite

Test case 1

  1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
  2: Deflater var1 = new java.util.zip.Deflater();;
  3: int var2 = 1078;;
  4: DeflaterOutputStream var3 = new java2.util2.zip2.DeflaterOutputStream(var0, var1, var2);;
  5: byte[] var4 = new byte[4];;
  6: try {
  7:   var3.write(var4, var2, var4[0]);
  8: } catch(IndexOutOfBoundsException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
  9: DeflaterOutputStream var6 = null;
 10: try {
 11:   var6 = new java2.util2.zip2.DeflaterOutputStream(var3, var1, var4[0]);
 12: } catch(IllegalArgumentException e) {}

Test case 2

  1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
  2: DeflaterOutputStream var1 = new java2.util2.zip2.DeflaterOutputStream(var0);;
  3: DeflaterOutputStream var2 = null;
  4: try {
  5:   var2 = new java2.util2.zip2.DeflaterOutputStream(var0, (Deflater) null);
  6: } catch(NullPointerException e) {}
  7: byte[] var3 = var1.buf;;
  8: try {
  9:   var1.write(var3, var3[6], var3[0]);
 10: }
 11: catch(IOException e) {} // Declared exception;
 12: DeflaterOutputStream var5 = null;
 13: try {
 14:   var5 = new java2.util2.zip2.DeflaterOutputStream((OutputStream) null);
 15: } catch(NullPointerException e) {}
 16: try {
 17:   var1.close();
 18: }
 19: catch(IOException e) {} // Declared exception;
 20: try {
 21:   var1.close();
 22: }
 23: catch(IOException e) {} // Declared exception;
 24: DeflaterOutputStream var8 = new java2.util2.zip2.DeflaterOutputStream(var1);;
 25: Deflater var9 = var1.def;;
 26: DeflaterOutputStream var10 = new java2.util2.zip2.DeflaterOutputStream(var0, var9);;
 27: try {
 28:   var8.write(var3[0]);
 29: } catch(IOException e) {} // Raised exception
 30: try {
 31:   var8.write(var3);
 32: }
 33: catch(IOException e) {} // Declared exception;
 34: try {
 35:   var10.close();
 36: }
 37: catch(IOException e) {} // Declared exception;

Source Code

  1: /*
  2:  * @(#)DeflaterOutputStream.java	1.37 10/03/23
  3:  *
  4:  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  5:  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6:  */
  7: 
  8: package java2.util2.zip2;
  9: 
 10: import java.io.FilterOutputStream;
 11: import java.io.OutputStream;
 12: import java.io.InputStream;
 13: import java.io.IOException;
 14: 
 15: import java.util.zip.Deflater;
 16: 
 17: /**
 18:  * This class implements an output stream filter for compressing data in
 19:  * the "deflate" compression format. It is also used as the basis for other
 20:  * types of compression filters, such as GZIPOutputStream.
 21:  *
 22:  * @see		Deflater
 23:  * @version 	1.37, 03/23/10
 24:  * @author 	David Connelly
 25:  */
 26: public
 27: class DeflaterOutputStream extends FilterOutputStream {
 28:     /**
 29:      * Compressor for this stream.
 30:      */
 31:     protected Deflater def;
 32: 
 33:     /**
 34:      * Output buffer for writing compressed data.
 35:      */
 36:     protected byte[] buf;
 37:    
 38:     /**
 39:      * Indicates that the stream has been closed.
 40:      */
 41: 
 42:     private boolean closed = false;
 43: 
 44:     /**
 45:      * Creates a new output stream with the specified compressor and
 46:      * buffer size.
 47:      * @param out the output stream
 48:      * @param def the compressor ("deflater")
 49:      * @param size the output buffer size
 50:      * @exception IllegalArgumentException if size is <= 0
 51:      */
 52:     public DeflaterOutputStream(OutputStream out, Deflater def, int size) {
 53:         super(out);
 54:         if (out == null || def == null) {
 55:             throw new NullPointerException();
 56:         } else if (size <= 0) {
 57:             throw new IllegalArgumentException("buffer size <= 0");
 58:         }
 59:         this.def = def;
 60:         buf = new byte[size];
 61:     }
 62: 
 63:     /**
 64:      * Creates a new output stream with the specified compressor and
 65:      * a default buffer size.
 66:      * @param out the output stream
 67:      * @param def the compressor ("deflater")
 68:      */
 69:     public DeflaterOutputStream(OutputStream out, Deflater def) {
 70: 	this(out, def, 512);
 71:     }
 72: 
 73:     boolean usesDefaultDeflater = false;
 74: 
 75:     /**
 76:      * Creates a new output stream with a default compressor and buffer size.
 77:      * @param out the output stream
 78:      */
 79:     public DeflaterOutputStream(OutputStream out) {
 80: 	this(out, new Deflater());
 81:         usesDefaultDeflater = true;
 82:     }
 83: 
 84:     /**
 85:      * Writes a byte to the compressed output stream. This method will
 86:      * block until the byte can be written.
 87:      * @param b the byte to be written
 88:      * @exception IOException if an I/O error has occurred
 89:      */
 90:     public void write(int b) throws IOException {
 91:         byte[] buf = new byte[1];
 92: 	buf[0] = (byte)(b & 0xff);
 93: 	write(buf, 0, 1);
 94:     }
 95: 
 96:     /**
 97:      * Writes an array of bytes to the compressed output stream. This
 98:      * method will block until all the bytes are written.
 99:      * @param b the data to be written
100:      * @param off the start offset of the data
101:      * @param len the length of the data
102:      * @exception IOException if an I/O error has occurred
103:      */
104:     public void write(byte[] b, int off, int len) throws IOException {
105: 	if (def.finished()) {
106: 	    throw new IOException("write beyond end of stream");
107: 	}
108:         if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
109: 	    throw new IndexOutOfBoundsException();
110: 	} else if (len == 0) {
111: 	    return;
112: 	}
113: 	if (!def.finished()) {
114:             // Deflate no more than stride bytes at a time.  This avoids
115:             // excess copying in deflateBytes (see Deflater.c)
116:             int stride = buf.length;
117:             for (int i = 0; i < len; i+= stride) {
118:                 def.setInput(b, off + i, Math.min(stride, len - i));
119:                 while (!def.needsInput()) {
120:                     deflate();
121:                 }
122:             }
123: 	}
124:     }
125: 
126:     /**
127:      * Finishes writing compressed data to the output stream without closing
128:      * the underlying stream. Use this method when applying multiple filters
129:      * in succession to the same output stream.
130:      * @exception IOException if an I/O error has occurred
131:      */
132:     public void finish() throws IOException {
133: 	if (!def.finished()) {
134: 	    def.finish();
135: 	    while (!def.finished()) {
136: 		deflate();
137: 	    }
138: 	}
139:     }
140: 
141:     /**
142:      * Writes remaining compressed data to the output stream and closes the
143:      * underlying stream.
144:      * @exception IOException if an I/O error has occurred
145:      */
146:     public void close() throws IOException {
147:         if (!closed) {
148:             finish();
149:             if (usesDefaultDeflater)
150:                 def.end();
151:             out.close();
152:             closed = true;
153:         }
154:     }
155: 
156:     /**
157:      * Writes next block of compressed data to the output stream.
158:      * @throws IOException if an I/O error has occurred
159:      */
160:     protected void deflate() throws IOException {
161: 	int len = def.deflate(buf, 0, buf.length);
162: 	if (len > 0) {
163: 	    out.write(buf, 0, len);
164: 	}
165:     }
166: }