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

"Unexpected end of input" #45

Open
GintsJekabsons opened this issue Sep 19, 2024 · 0 comments
Open

"Unexpected end of input" #45

GintsJekabsons opened this issue Sep 19, 2024 · 0 comments

Comments

@GintsJekabsons
Copy link

GintsJekabsons commented Sep 19, 2024

Hi!

I have found a file compression and decompression of which causes the following exception:

Exception in thread "main" java.io.IOException: unexpected end of input
	at com.nixxcode.jvmbrotli.dec.Decoder.fail(Decoder.java:50)
	at com.nixxcode.jvmbrotli.dec.Decoder.decode(Decoder.java:90)
	at com.nixxcode.jvmbrotli.dec.BrotliInputStream.read(BrotliInputStream.java:59)
	at Test.main(Test.java:120)

The file:
test.txt

The code (I run it in Java 8):

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.apache.commons.io.output.ByteArrayOutputStream;

import com.nixxcode.jvmbrotli.common.BrotliLoader;
import com.nixxcode.jvmbrotli.dec.BrotliInputStream;
import com.nixxcode.jvmbrotli.enc.BrotliOutputStream;
import com.nixxcode.jvmbrotli.enc.Encoder;

public class Test {
	public static void main(String[] args) throws IOException {
		if (!BrotliLoader.isBrotliAvailable()) {
			System.out.println("Brotli not available");
			return;
		}
		byte[] bytes = Files.readAllBytes(new File("H:/Brotli/test.txt").toPath());

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		BrotliOutputStream brotliOutputStream = new BrotliOutputStream(baos, new Encoder.Parameters().setQuality(2));
		brotliOutputStream.write(bytes);
		brotliOutputStream.close();

		InputStream is = new ByteArrayInputStream(baos.toByteArray());
		BrotliInputStream brotliInputStream = new BrotliInputStream(is);
		while (brotliInputStream.read() != -1) {}
		brotliInputStream.close();
	}
}

Expected behavior: the program does no output, just silently compresses and decompresses a file.

Actual behavior: the program raises the mentioned exception when the quality in setQuality() is set to at least 2. If lower, no exception.

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

No branches or pull requests

1 participant