28package com.jogamp.common.util;
31import java.io.FileInputStream;
32import java.io.FileOutputStream;
33import java.io.IOException;
34import java.io.InputStream;
35import java.io.OutputStream;
38 public static void main(
final String[] args) {
39 if (args.length != 2) {
40 System.err.println(
"Usage: java "+
CustomDeflate.class.getName()+
" file-in file-out");
42 final File fileIn =
new File(args[0]);
43 final File fileOut =
new File(args[1]);
46 final long _inSize = fileIn.length();
47 if( 0 >= _inSize || _inSize > Integer.MAX_VALUE ) {
48 throw new IllegalArgumentException(
"");
50 inSize = (int) _inSize;
52 final byte[] input =
new byte[inSize];
53 InputStream in =
null;
54 OutputStream out =
null;
56 in =
new FileInputStream(fileIn);
60 final int remBytes = inSize - numBytes;
62 if ( 0 >= remBytes || (count = in.read(input, numBytes, remBytes)) == -1 ) {
70 if( inSize != numBytes ) {
71 throw new IOException(
"Got "+numBytes+
" bytes != expected "+inSize);
73 out =
new FileOutputStream(fileOut);
75 }
catch (
final IOException ioe) {
76 ioe.printStackTrace();
79 try { in.close(); }
catch (
final IOException e) { }
82 try { out.close(); }
catch (
final IOException e) { }
92 in =
new FileInputStream(fileOut);
94 if( compare.length != inSize ) {
95 throw new InternalError(
"Inflated Size Mismatch: Has "+compare.length+
", expected "+inSize);
97 for(
int i=0; i<inSize; i++) {
98 if( input[i] != compare[i] ) {
99 throw new InternalError(
"Inflated Bytes Mismatch at "+i+
"/"+inSize+
": Has "+Integer.toHexString(compare[i])+
", expected "+Integer.toHexString(input[i]));
102 }
catch (
final IOException ioe) {
103 ioe.printStackTrace();
106 try { in.close(); }
catch (
final IOException e) { }
109 try { out.close(); }
catch (
final IOException e) { }
All in memory inflater / deflator for small chunks using streams.
static byte[] inflateFromStream(final InputStream in)
static int deflateToStream(final byte[] input, final int inOff, final int inLen, final int level, final OutputStream out)
static void main(final String[] args)