如何使用java解压缩LZO文件(使用库LZO-core)



我在尝试使用java解压缩LZO文件时遇到了这个问题。下面是我粘贴的代码和错误,有人能帮我处理这个吗

import org.anarres.lzo.*;

import java.io.*;

public class LZODecompression {

public static void  main(String args[]) throws IOException {

InputStream in = new FileInputStream(new 
File("/desktop/mm_impressions_101349_20220723_2022072802.txt.lzo"));
LzoAlgorithm algorithm = LzoAlgorithm.LZO1X;
LzoDecompressor decompressor = LzoLibrary.getInstance().newDecompressor(algorithm, 
null);
LzoInputStream stream = new LzoInputStream(in, decompressor);
OutputStream outputStream = new FileOutputStream(new File("/Desktop/test.txt"));
int len;
byte[] bytes = new byte[1024];

while ((len = stream.read(bytes)) != -1) {
outputStream.write(bytes, 0, len);
}
outputStream.close();
stream.close();
}
}

Exception in thread "main" java.io.EOFException
at org.anarres.lzo.LzoInputStream.readBytes(LzoInputStream.java:183)
at org.anarres.lzo.LzoInputStream.readBlock(LzoInputStream.java:132)
at org.anarres.lzo.LzoInputStream.fill(LzoInputStream.java:119)
at org.anarres.lzo.LzoInputStream.read(LzoInputStream.java:102)
at org.anarres.lzo.LzoInputStream.read(LzoInputStream.java:97)
at org.example.LZODecompression.main(LZODecompression.java:37)

我使用了LzoInputStream,而不是LzoInputStream并且该文件在Linux中成功解压缩。我使用了以下代码:

public static void decompressOriginal() throws Exception
{
String basePath = "/home/saad/CompressionTest/";
String compressedFileName = "temp1.lzo";
String afterDecompressFilename = "temp1.txt";
System.out.println("Decompressing:" + compressedFileName);
InputStream in = new FileInputStream(new File(basePath + compressedFileName));
LzoInputStream stream = new LzopInputStream(in);
OutputStream outputStream = new FileOutputStream(new File(basePath + afterDecompressFilename));
int len;
byte[] bytes = new byte[256];
while ((len = stream.read(bytes)) != -1)
{
outputStream.write(bytes, 0, len);
}
outputStream.close();
stream.close();
System.out.println("Successfully Decompressed:" + afterDecompressFilename);
}

然而,我使用了以下代码来压缩文件:

public static void compressFile() throws IOException
{
String basePath = "/home/saad/CompressionTest/";
String sourceFile = "source1.sql";
String destinationFile = "temp1.lzo";
File plainTextFile = new File(basePath + sourceFile);
InputStream inputStream = new FileInputStream(plainTextFile);
byte[] byteArray = org.apache.commons.io.IOUtils.toByteArray(inputStream);
inputStream.close();
System.out.println("File:" + sourceFile + " Array Size:" + byteArray.length);
LzoCompressor compressor = LzoLibrary.getInstance().newCompressor(LzoAlgorithm.LZO1X, null);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
LzopOutputStream lzopOutputStream = new LzopOutputStream(outputStream, compressor, 1024 * 100, LzopConstants.F_ADLER32_C);
lzopOutputStream.write(byteArray);
lzopOutputStream.close();
System.out.println("Compression Complete:" + sourceFile);
org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(basePath + destinationFile), outputStream.toByteArray());
System.out.println("Written File:" + destinationFile);
}

因为当我使用系统软件进行压缩时,它给出了以下错误:

线程中的异常"主";java.io.IOException:压缩不兼容的lzo版本:0x2080(应为0x2050(因为LZO压缩是更新的,但我无法得到更新版本的使用库。

我们需要使用其他支持最新LZO版本的库。

最新更新