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