1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.eclipse.jetty.spdy;
18
19 import java.util.zip.DataFormatException;
20 import java.util.zip.Deflater;
21 import java.util.zip.Inflater;
22 import java.util.zip.ZipException;
23
24 public class StandardCompressionFactory implements CompressionFactory
25 {
26 @Override
27 public Compressor newCompressor()
28 {
29 return new StandardCompressor();
30 }
31
32 @Override
33 public Decompressor newDecompressor()
34 {
35 return new StandardDecompressor();
36 }
37
38 public static class StandardCompressor implements Compressor
39 {
40 private final Deflater deflater = new Deflater();
41
42 @Override
43 public void setInput(byte[] input)
44 {
45 deflater.setInput(input);
46 }
47
48 @Override
49 public void setDictionary(byte[] dictionary)
50 {
51 deflater.setDictionary(dictionary);
52 }
53
54 @Override
55 public int compress(byte[] output)
56 {
57 return deflater.deflate(output, 0, output.length, Deflater.SYNC_FLUSH);
58 }
59 }
60
61 public static class StandardDecompressor implements CompressionFactory.Decompressor
62 {
63 private final Inflater inflater = new Inflater();
64
65 @Override
66 public void setDictionary(byte[] dictionary)
67 {
68 inflater.setDictionary(dictionary);
69 }
70
71 @Override
72 public void setInput(byte[] input)
73 {
74 inflater.setInput(input);
75 }
76
77 @Override
78 public int decompress(byte[] output) throws ZipException
79 {
80 try
81 {
82 return inflater.inflate(output);
83 }
84 catch (DataFormatException x)
85 {
86 throw (ZipException)new ZipException().initCause(x);
87 }
88 }
89 }
90 }