Path: blob/main/epkcompiler/src/com/jcraft/jzlib/GZIPOutputStream.java
8645 views
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/*2Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are met:671. Redistributions of source code must retain the above copyright notice,8this list of conditions and the following disclaimer.9102. Redistributions in binary form must reproduce the above copyright11notice, this list of conditions and the following disclaimer in12the documentation and/or other materials provided with the distribution.13143. The names of the authors may not be used to endorse or promote products15derived from this software without specific prior written permission.1617THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,18INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND19FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,20INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,23OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF24LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING25NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,26EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/2829package com.jcraft.jzlib;30import java.io.*;3132public class GZIPOutputStream extends DeflaterOutputStream {3334public GZIPOutputStream(OutputStream out) throws IOException {35this(out, DEFAULT_BUFSIZE);36}3738public GZIPOutputStream(OutputStream out, int size) throws IOException {39this(out, size, true);40}4142public GZIPOutputStream(OutputStream out,43int size,44boolean close_out) throws IOException {45this(out,46new Deflater(JZlib.Z_DEFAULT_COMPRESSION, 15+16),47size, close_out);48mydeflater=true;49}5051public GZIPOutputStream(OutputStream out,52Deflater deflater,53int size,54boolean close_out) throws IOException{55super(out, deflater, size, close_out);56}575859private void check() throws GZIPException {60if(deflater.dstate.status != 42 /*INIT_STATUS*/)61throw new GZIPException("header is already written.");62}6364public void setModifiedTime(long mtime) throws GZIPException {65check();66deflater.dstate.getGZIPHeader().setModifiedTime(mtime);67}6869public void setOS(int os) throws GZIPException {70check();71deflater.dstate.getGZIPHeader().setOS(os);72}7374public void setName(String name) throws GZIPException {75check();76deflater.dstate.getGZIPHeader().setName(name);77}7879public void setComment(String comment) throws GZIPException {80check();81deflater.dstate.getGZIPHeader().setComment(comment);82}8384public long getCRC() throws GZIPException {85if(deflater.dstate.status != 666 /*FINISH_STATE*/)86throw new GZIPException("checksum is not calculated yet.");87return deflater.dstate.getGZIPHeader().getCRC();88}89}909192