Pregunta

all

I faced a problem to compress and decompress between java and C++.

Here is Java code runs at server.

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();
}

And I receive a binary file from server.

Then I have to decompress it using C++.

Where do I start with?

¿Fue útil?

Solución

Your compression program uses zlib (see JDK documentation), so you need to use a C++ zlib library to decompress its output.

The zlib documentation is the place to start.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top