Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I decompress Framed Format files? #273

Open
egorbarkovsky opened this issue Dec 2, 2020 · 1 comment
Open

How can I decompress Framed Format files? #273

egorbarkovsky opened this issue Dec 2, 2020 · 1 comment
Labels

Comments

@egorbarkovsky
Copy link

Sorry, but how can I decompress Framed Format files?

@egorbarkovsky
Copy link
Author

  public static void main(String[] args) throws IOException {
        FileInputStream file = new FileInputStream("DataList.txt");
        byte[] compressed = compressFrame(file.readAllBytes());
        for (byte b: compressed) {
            System.out.print(b + " ");
        }
        byte[] decompressed = uncompressFrames(compressFrame(input)); **//why null?**
    }


    public static byte[] compressFrame(byte[] input) throws IOException {
        try(ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(input.length)) {
            try(SnappyFramedOutputStream snappyFramedOutputStream = new SnappyFramedOutputStream(byteArrayOutputStream)) {
                snappyFramedOutputStream.write(input);
                snappyFramedOutputStream.flush();
                return byteArrayOutputStream.toByteArray();
            }
        }
    }

    public static byte[] uncompressFrames(byte[] input)
            throws IOException
    {
        try(ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input)) {
            try(SnappyFramedInputStream snappyFramedInputStream = new SnappyFramedInputStream(byteArrayInputStream, false)) {
                try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
                    snappyFramedInputStream.transferTo(byteArrayOutputStream);
                    return byteArrayInputStream.readAllBytes();
                }
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants