-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathPpmCompressTest.java
More file actions
37 lines (30 loc) · 995 Bytes
/
Copy pathPpmCompressTest.java
File metadata and controls
37 lines (30 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Reference arithmetic coding
*
* Copyright (c) Project Nayuki
* MIT License. See readme file.
* https://www.nayuki.io/page/reference-arithmetic-coding
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Tests {@link PpmCompress} coupled with {@link PpmDecompress}.
*/
public class PpmCompressTest extends ArithmeticCodingTest {
protected byte[] compress(byte[] b) throws IOException {
InputStream in = new ByteArrayInputStream(b);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (BitOutputStream bitOut = new BitOutputStream(out)) {
PpmCompress.compress(in, bitOut);
}
return out.toByteArray();
}
protected byte[] decompress(byte[] b) throws IOException {
InputStream in = new ByteArrayInputStream(b);
ByteArrayOutputStream out = new ByteArrayOutputStream();
PpmDecompress.decompress(new BitInputStream(in), out);
return out.toByteArray();
}
}