全部
我遇到了在 java 和 C++ 之间压缩和解压缩的问题。
这是在服务器上运行的 Java 代码。
public static byte[] CompressByDeflater(byte[] toCompress) throws IOException
{
ByteArrayOutputStream compressedStream = new ByteArrayOutputStream();
DeflaterOutputStream inflater = new DeflaterOutputStream(compressedStream);
inflater.write(toCompress, 0, toCompress.length);
inflater.close();
return compressedStream.toByteArray();
}
public static byte[] DecompressByInflater(byte[] toDecompress) throws IOException
{
ByteArrayOutputStream uncompressedStream = new ByteArrayOutputStream();
ByteArrayInputStream compressedStream = new ByteArrayInputStream(toDecompress);
InflaterInputStream inflater = new InflaterInputStream(compressedStream);
int c;
while ((c = inflater.read()) != -1)
{
uncompressedStream.write(c);
}
return uncompressedStream.toByteArray();
}
我从服务器收到一个二进制文件。
然后我必须使用 C++ 解压缩它。
我从哪里开始?
最佳答案
您的压缩程序使用 zlib(参见 JDK documentation),因此您需要使用 C++ zlib 库来解压缩其输出。
zlib documentation是开始的地方。
关于java - C++和Java之间如何压缩和解压?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22267583/