Skip to content

Instantly share code, notes, and snippets.

@osima
Created January 14, 2012 23:05
Show Gist options
  • Save osima/1613288 to your computer and use it in GitHub Desktop.
Save osima/1613288 to your computer and use it in GitHub Desktop.
decode flate-decode part how to in pdf
import java.io.*;
import java.util.*;
import java.util.zip.*;
class ProcessFlateDecode {
private File f;
public ProcessFlateDecode(File f){
this.f=f;
}
public void process() throws Exception{
ArrayList list = new ArrayList();
FileInputStream ins = new FileInputStream(f);
while(true){
int data = ins.read();
if(data==-1) break;
list.add( data );
}
ins.close();
int compressedDataLength = list.size();
byte[] output = new byte[compressedDataLength];
for(int i=0; i<list.size(); i++){
Integer o=(Integer)list.get(i);
output[i]=(byte)(o.intValue());
}
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();
String outputString = new String(result, 0, resultLength, "UTF-8");
System.out.println(outputString);
}
public static void main(String[] args) throws Exception{
new Decode(new File(args[0])).process();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment