1 /* ZNet - Java Compression Layer for a new Socket Factory
2 Copyright (C) 1999, Free Software Rulez
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 The author of this program may be contacted at morgiaclaudio@yahoo.it. */
19
20 package java.net;
21
22 import java.util.zip;
23
24 /**
25 * This class is the default compressor used in our compression layer.
26 * It merely implements the Compressor interface through direct inclusion
27 * of the Deflater class (that provided the idea of the Compressor interface).
28 * The only plus is the compression level number calculation and some utility method.
29 * @see java.util.zip.Deflater the standard <i>back-office</i> implementation
30 * @see java.net.Compressor the interface
31 * @author <a href="mailto:morgiaclaudio@yahoo.it">Claudio Morgia</a>
32 * @version 1.0
33 */
34 public class DeflatingCompressor extends Deflater implements Compressor {
35 /**
36 * The actual working level of the compressor instance.
37 */
38 protected int level;
39
40 /**
41 * The number of supported compression level.
42 */
43 protected static int numlevels;
44
45 static {
46 numlevels=Deflater.BEST_COMPRESSION-Deflater.NO_COMPRESSION+1;
47 }
48
49 /**
50 * This method sets the working level of the compression engine and store it into the
51 * {@link #level level} field.
52 * @param l level to use
53 */
54 public synchronized void setLevel(int l) {
55 super.setLevel(l);
56 level=l;
57 }
58
59 /**
60 * This method returns the actual working level.
61 * @return actual working level
62 */
63 public int getLevel() {
64 return level;
65 }
66
67 /**
68 * This method returns the number of supported compression levels.
69 * @return the number of supported levels
70 */
71 public int getLevels() {
72 return numlevels;
73 }
74 }