मैं zlib संपीड़न के लिए java.util.zip में Deflate और Inflate कक्षाओं का उपयोग करने का प्रयास करना चाहता हूं।ज़्लिब संपीड़न जावा में डिफ्लेट और इन्फ्लेट कक्षाओं का उपयोग
मैं Deflate का उपयोग कर कोड को संपीड़ित करने में सक्षम हूँ, लेकिन जब decompressing, मैं इस त्रुटि हो रहा है -
Exception in thread "main" java.util.zip.DataFormatException: unknown compression method
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:238)
at java.util.zip.Inflater.inflate(Inflater.java:256)
at zlibCompression.main(zlibCompression.java:53)
यहाँ मेरी कोड अब तक है -
import java.util.zip.*;
import java.io.*;
public class zlibCompression {
/**
* @param args
*/
public static void main(String[] args) throws IOException, DataFormatException {
// TODO Auto-generated method stub
String fname = "book1";
FileReader infile = new FileReader(fname);
BufferedReader in = new BufferedReader(infile);
FileOutputStream out = new FileOutputStream("book1out.dfl");
//BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
Deflater compress = new Deflater();
Inflater decompress = new Inflater();
String readFile = in.readLine();
byte[] bx = readFile.getBytes();
while(readFile!=null){
byte[] input = readFile.getBytes();
byte[] compressedData = new byte[1024];
compress.setInput(input);
compress.finish();
int compressLength = compress.deflate(compressedData, 0, compressedData.length);
//System.out.println(compressedData);
out.write(compressedData, 0, compressLength);
readFile = in.readLine();
}
File abc = new File("book1out.dfl");
InputStream is = new FileInputStream("book1out.dfl");
InflaterInputStream infl = new InflaterInputStream(new FileInputStream("book1out.dfl"), new Inflater());
FileOutputStream outFile = new FileOutputStream("decompressed.txt");
byte[] b = new byte[1024];
while(true){
int a = infl.read(b,0,1024);
if(a==0)
break;
decompress.setInput(b);
byte[] fresult = new byte[1024];
//decompress.in
int resLength = decompress.inflate(fresult);
//outFile.write(b,0,1);
//String outt = new String(fresult, 0, resLength);
//System.out.println(outt);
}
System.out.println("complete");
}
}
एक होमवर्क है? एक गलती बहुत जल्दी खत्म हो रही है, दूसरा दूसरा setInput w/o लंबाई का उपयोग कर रहा है और एक और यह जांच नहीं कर रहा है कि डिफ्लेट प्रक्रिया 1024 से अधिक डेटा लौटा दी है। – bestsss