private static byte[] zipText(byte[] licenseText) throws IOException { int len; byte[] buff = new byte[64]; ByteArrayInputStream in = new ByteArrayInputStream(licenseText); DeflaterInputStream deflater = new DeflaterInputStream(in, new Deflater()); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { while ((len = deflater.read(buff)) > 0) { out.write(buff, 0, len); } return out.toByteArray(); } finally { out.close(); deflater.close(); in.close(); } }
private static byte[] deflate(byte[] orig) throws ItlException { try { DeflaterInputStream isDeflater = new DeflaterInputStream(new ByteArrayInputStream(orig), new Deflater()); ByteArrayOutputStream osCompressed = new ByteArrayOutputStream(orig.length); byte[] deflated = new byte[orig.length]; int iCompressed; while(true) { iCompressed = isDeflater.read(deflated, 0, orig.length); if (iCompressed == -1) break; osCompressed.write(deflated, 0, iCompressed); } deflated = osCompressed.toByteArray(); osCompressed.close(); isDeflater.close(); return deflated; } catch (IOException ioe) { throw new ItlException("Error when zipping the file contents", ioe); } }
final int r = super.read(b, off + count, i); if (r < i) {
public int read(byte b[], int off, int len) throws IOException { // Check if there are bytes left to be read from the internal buffer. This is used to provide the header // or trailer, and always takes precedence. int count; if (buffer.getByteCountRemainder() > 0) { // Write data from the internal buffer into b. count = Math.min(len, buffer.getByteCountRemainder()); System.arraycopy(buffer.data, buffer.position, b, off, count); // Advance the internal buffer position as "count" bytes have already been read. buffer.position += count; return count; } // Attempt to read compressed input data. count = super.read(b, off, len); if (count > 0) { return count; } /* * If the stream has reached completion, write out the GZIP trailer and re-attempt the read */ if (count <= 0 && !trailerWritten) { buffer.position = 0; buffer.length = writeTrailer(buffer.data, buffer.position); trailerWritten = true; return read(b, off, len); } else { return count; } }
count = super.read(b, off, len); if (count > 0)