Skip to content

Commit 0e6ac0f

Browse files
committed
Java implementation
1 parent 6670d69 commit 0e6ac0f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

java/src/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: isc.zlib.Java
3+

java/src/isc/zlib/Java.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package isc.zlib;
2+
3+
import java.util.Arrays;
4+
import java.util.zip.Deflater;
5+
6+
public abstract class Java {
7+
8+
public static byte[] compress(String inputString) {
9+
byte[] output = new byte[100];
10+
try {
11+
// Encode a String into bytes
12+
byte[] input = inputString.getBytes("UTF-8");
13+
14+
// Compress the bytes
15+
16+
Deflater compresser = new Deflater();
17+
compresser.setInput(input);
18+
compresser.finish();
19+
int compressedDataLength = compresser.deflate(output);
20+
compresser.end();
21+
output = Arrays.copyOfRange(output, 0, compressedDataLength);
22+
23+
} catch (java.io.UnsupportedEncodingException ex) {
24+
// handle
25+
}
26+
27+
28+
return output;
29+
}
30+
}

0 commit comments

Comments
 (0)