你好,我试图为物品制作一个压缩器,但我似乎不太明白,我有一个原始文件,我正在测试,例如(items.dat,idx)我的解压缩器将其全部解压缩,但是当我使用压缩器时然后将其测试到一个项目会给我一个错误。
java.io.EOFException
Extracted: 876 models!
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readFully(Unknown Source)
at ModelRipper.decompress(ModelRipper.java:46)
at ModelRipper.main(ModelRipper.java:27)
我的第46行: Line with method
我的解压缩方法:
public static void decompress() {
try {
GZIPInputStream gzipDataFile = new GZIPInputStream(new FileInputStream(signlink.findcachedir() + userInput + ".dat"));
DataInputStream dataFile = new DataInputStream(gzipDataFile);
GZIPInputStream gzipIndexFile = new GZIPInputStream(new FileInputStream(signlink.findcachedir() + userInput + ".idx"));
DataInputStream indexFile = new DataInputStream(gzipIndexFile);
int length = indexFile.readInt();
for(int i = 0; i < length; i++) {
int id = indexFile.readInt();
int invlength = indexFile.readInt();
byte[] data = new byte[invlength];
dataFile.readFully(data);
System.out.println(id);
System.out.println(invlength);
Model.method460(data, id);
FileOutputStream fos = new FileOutputStream("./MODELS1/"+id+".dat");
modelsExtracted++;
fos.write(data);
fos.flush();
fos.close();
}
indexFile.close();
dataFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}
我的压缩方法:
public static void compress() throws FileNotFoundException, IOException {
try {
File file = new File("./MODELS/");
GZIPOutputStream gzipDataFile = new GZIPOutputStream(new FileOutputStream("./" + userInput + ".dat"));
DataOutputStream dataFile = new DataOutputStream(gzipDataFile);
GZIPOutputStream gzipIndexFile = new GZIPOutputStream(new FileOutputStream("./" + userInput + ".idx"));
DataOutputStream indexFile = new DataOutputStream(gzipIndexFile);
File[] fileArray = file.listFiles();
for (int y = 0; y < fileArray.length; y++) {
String s = fileArray[y].getName();
byte[] buffer = ReadFile("./MODELS/" + s);
modelsExtracted++;
int invlength = (int) fileArray[y].length();
int id = Integer.parseInt(getFileNameWithoutExtension(s));
indexFile.writeInt(id);
//indexFile.flush();
indexFile.writeInt(invlength);
indexFile.flush();
System.out.println(id);
System.out.println(invlength);
dataFile.write(buffer);
dataFile.flush();
}
indexFile.close();
dataFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}