MCPcopy Create free account
hub / github.com/Java-Techie-jt/file-storage / ImageUtils

Class ImageUtils

src/main/java/com/javatechie/util/ImageUtils.java:7–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import java.util.zip.Inflater;
6
7public class ImageUtils {
8
9
10 public static byte[] compressImage(byte[] data) {
11 Deflater deflater = new Deflater();
12 deflater.setLevel(Deflater.BEST_COMPRESSION);
13 deflater.setInput(data);
14 deflater.finish();
15
16 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
17 byte[] tmp = new byte[4*1024];
18 while (!deflater.finished()) {
19 int size = deflater.deflate(tmp);
20 outputStream.write(tmp, 0, size);
21 }
22 try {
23 outputStream.close();
24 } catch (Exception ignored) {
25 }
26 return outputStream.toByteArray();
27 }
28
29
30
31 public static byte[] decompressImage(byte[] data) {
32 Inflater inflater = new Inflater();
33 inflater.setInput(data);
34 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
35 byte[] tmp = new byte[4*1024];
36 try {
37 while (!inflater.finished()) {
38 int count = inflater.inflate(tmp);
39 outputStream.write(tmp, 0, count);
40 }
41 outputStream.close();
42 } catch (Exception ignored) {
43 }
44 return outputStream.toByteArray();
45 }
46
47}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected