如何在C 和Java之间压缩和解压缩
How to compress and decompress between C++ and Java?
asl
我面临一个问题,可以在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文档),因此您需要使用C Zlib库来解压缩其输出。
Zlib文档是开始的地方。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- C++中高效的大型稀疏块压缩线性方程
- 嵌入方指针压缩已禁用
- int(c) 和 c-'0' 之间的区别。C++
- C++使用整数的压缩数组初始化对象
- 在cuda线程之间共享大量常量数据
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- 在C++中将函数压缩为两种方式
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 类与私有变量的其他类之间的线程安全性
- 如何在cpp文件之间切换窗口?在Qt中
- 线程之间的布尔停止信号
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在压缩和未压缩数据之间切换
- 如何在C 和Java之间压缩和解压缩
- Boost序列化在32位和64位机器之间不工作.任何其他序列化/压缩库