comparison app/src/main/java/com/jcraft/jzlib/Deflater.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/com/jcraft/jzlib/Deflater.java@46c2115ae1c8
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 /*
3 Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
14
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 /*
30 * This program is based on zlib-1.1.3, so all credit should go authors
31 * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
32 * and contributors of zlib.
33 */
34
35 package com.jcraft.jzlib;
36
37 final public class Deflater extends ZStream{
38
39 static final private int MAX_WBITS=15; // 32K LZ77 window
40 static final private int DEF_WBITS=MAX_WBITS;
41
42 static final private int Z_NO_FLUSH=0;
43 static final private int Z_PARTIAL_FLUSH=1;
44 static final private int Z_SYNC_FLUSH=2;
45 static final private int Z_FULL_FLUSH=3;
46 static final private int Z_FINISH=4;
47
48 static final private int MAX_MEM_LEVEL=9;
49
50 static final private int Z_OK=0;
51 static final private int Z_STREAM_END=1;
52 static final private int Z_NEED_DICT=2;
53 static final private int Z_ERRNO=-1;
54 static final private int Z_STREAM_ERROR=-2;
55 static final private int Z_DATA_ERROR=-3;
56 static final private int Z_MEM_ERROR=-4;
57 static final private int Z_BUF_ERROR=-5;
58 static final private int Z_VERSION_ERROR=-6;
59
60 private boolean finished = false;
61
62 public Deflater(){
63 super();
64 }
65
66 public Deflater(int level) throws GZIPException {
67 this(level, MAX_WBITS);
68 }
69
70 public Deflater(int level, boolean nowrap) throws GZIPException {
71 this(level, MAX_WBITS, nowrap);
72 }
73
74 public Deflater(int level, int bits) throws GZIPException {
75 this(level, bits, false);
76 }
77
78 public Deflater(int level, int bits, boolean nowrap) throws GZIPException {
79 super();
80 int ret = init(level, bits, nowrap);
81 if(ret!=Z_OK)
82 throw new GZIPException(ret+": "+msg);
83 }
84
85 public Deflater(int level, int bits, int memlevel, JZlib.WrapperType wrapperType) throws GZIPException {
86 super();
87 int ret = init(level, bits, memlevel, wrapperType);
88 if(ret!=Z_OK)
89 throw new GZIPException(ret+": "+msg);
90 }
91
92 public Deflater(int level, int bits, int memlevel) throws GZIPException {
93 super();
94 int ret = init(level, bits, memlevel);
95 if(ret!=Z_OK)
96 throw new GZIPException(ret+": "+msg);
97 }
98
99 public int init(int level){
100 return init(level, MAX_WBITS);
101 }
102 public int init(int level, boolean nowrap){
103 return init(level, MAX_WBITS, nowrap);
104 }
105 public int init(int level, int bits){
106 return init(level, bits, false);
107 }
108 public int init(int level, int bits, int memlevel, JZlib.WrapperType wrapperType){
109 if(bits < 9 || bits > 15){
110 return Z_STREAM_ERROR;
111 }
112 if(wrapperType == JZlib.W_NONE) {
113 bits *= -1;
114 }
115 else if(wrapperType == JZlib.W_GZIP) {
116 bits += 16;
117 }
118 else if(wrapperType == JZlib.W_ANY) {
119 return Z_STREAM_ERROR;
120 }
121 else if(wrapperType == JZlib.W_ZLIB) {
122 }
123 return init(level, bits, memlevel);
124 }
125 public int init(int level, int bits, int memlevel){
126 finished = false;
127 dstate=new Deflate(this);
128 return dstate.deflateInit(level, bits, memlevel);
129 }
130 public int init(int level, int bits, boolean nowrap){
131 finished = false;
132 dstate=new Deflate(this);
133 return dstate.deflateInit(level, nowrap?-bits:bits);
134 }
135
136 public int deflate(int flush){
137 if(dstate==null){
138 return Z_STREAM_ERROR;
139 }
140 int ret = dstate.deflate(flush);
141 if(ret == Z_STREAM_END)
142 finished = true;
143 return ret;
144 }
145 public int end(){
146 finished = true;
147 if(dstate==null) return Z_STREAM_ERROR;
148 int ret=dstate.deflateEnd();
149 dstate=null;
150 free();
151 return ret;
152 }
153 public int params(int level, int strategy){
154 if(dstate==null) return Z_STREAM_ERROR;
155 return dstate.deflateParams(level, strategy);
156 }
157 public int setDictionary (byte[] dictionary, int dictLength){
158 if(dstate == null)
159 return Z_STREAM_ERROR;
160 return dstate.deflateSetDictionary(dictionary, dictLength);
161 }
162
163 public boolean finished(){
164 return finished;
165 }
166
167 public int copy(Deflater src){
168 this.finished = src.finished;
169 return Deflate.deflateCopy(this, src);
170 }
171 }