Git Product home page Git Product logo

Comments (2)

fatcarter avatar fatcarter commented on August 24, 2024

when called main method:

13:39:00.620 [main] INFO compress - char length=3,byte array length=3
13:39:00.627 [main] INFO compress - compressed:char length=35,byte array length=35
13:39:00.627 [main] INFO compress - value=123������������������������������
Exception in thread "main" io.airlift.compress.MalformedInputException: Malformed input: offset=5
	at io.airlift.compress.snappy.SnappyRawDecompressor.uncompressAll(SnappyRawDecompressor.java:124)
	at io.airlift.compress.snappy.SnappyRawDecompressor.decompress(SnappyRawDecompressor.java:53)
	at io.airlift.compress.snappy.SnappyDecompressor.decompress(SnappyDecompressor.java:101)

from aircompressor.

dain avatar dain commented on August 24, 2024

I'm not sure what is wrong with the ByteBuffer code, but this will work:

    public byte[] compress(String s)
    {
        byte[] data = s.getBytes(StandardCharsets.UTF_8);
        int length = compressor.maxCompressedLength(data.length);
        byte[] out = new byte[length];
        int size = compressor.compress(data, 0, data.length, out, 0, out.length);
        return Arrays.copyOf(out, size);
    }

    public String decompress(byte[] compressed)
    {
        int length = decompressor.getUncompressedLength(compressed, 0);
        byte[] out = new byte[length];
        int size = decompressor.decompress(compressed, 0, compressed.length, out, 0, out.length);
        return new String(out,0, size, StandardCharsets.UTF_8);
    }

There are extensive tests for correctness that look like the above, so if you are looking for sample code checkout the tests.

from aircompressor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.