我的目标是在C ++中使用LZ4压缩文件并在Java中对其进行解压缩。
我的文本文件(A.txt):
TextFormField
c ++压缩后的文件(A.txt.lz4):
// wrap it with an Expanded widget
Expanded(
child: TextFormField(
// set the keyboard type to multiline f
keyboardType: TextInputType.multiline,
// set maxlines to null
maxLines: null,
// set expands to true
expands: true,
decoration: InputDecoration(
isDense: true,
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black)
)
),
),
),
然后我用Java(B.txt)解压缩了它:
Hi, Hello everyone.
Thanks.
问题是我没有得到每个文件的第一个字符。我不知道哪里出了问题。
我的Java代码:
"M@Pw €Hi, Hello everyone.
Thanks.
任何帮助都是有用的。预先感谢。
答案 0 :(得分:1)
有一个factory用于创建应检查的流:
CompressorInputStream zIn =
new CompressorStreamFactory()
.createCompressorInputStream(CompressorStreamFactory.LZ4_BLOCK, in);
或LZ4_FRAMED
,具体取决于C ++库生成的内容。
答案 1 :(得分:0)
感谢大家的帮助。我使用此代码对其进行了修复。
public static void uncompressLz4File(String str1, String str2) {
File f1 = new File(str1);
File f2 = new File(str2);
try (FileInputStream fin = new FileInputStream(f1);
BufferedInputStream in = new BufferedInputStream(fin);
OutputStream out = Files.newOutputStream(Paths.get(f2.getAbsolutePath()));
FramedLZ4CompressorInputStream zIn = new FramedLZ4CompressorInputStream(in)) {
int n;
byte[] b = new byte[1024];
while ((n = zIn.read(b)) > 0) {
out.write(b, 0, n);
}
} catch (Exception e) {
e.printStackTrace();
}
}