本文整理汇总了Java中java.util.zip.GZIPOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java GZIPOutputStream.finish方法的具体用法?Java GZIPOutputStream.finish怎么用?Java GZIPOutputStream.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.GZIPOutputStream
的用法示例。
在下文中一共展示了GZIPOutputStream.finish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public byte[] compress( final byte[] data , final int start , final int length ) throws IOException{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
GZIPOutputStream out = new GZIPOutputStream( bOut );
out.write( data , start , length );
out.flush();
out.finish();
byte[] compressByte = bOut.toByteArray();
byte[] retVal = new byte[ Integer.BYTES + compressByte.length ];
ByteBuffer wrapBuffer = ByteBuffer.wrap( retVal );
wrapBuffer.putInt( length );
wrapBuffer.put( compressByte );
bOut.close();
out.close();
return retVal;
}
示例2: gzipFile
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private File gzipFile(File src) throws IOException {
// Never try to make it stream-like on the fly, because content-length still required
// Create the GZIP output stream
String outFilename = src.getAbsolutePath() + ".gz";
notifier.notifyAbout("Gzipping " + src.getAbsolutePath());
GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename), 1024 * 8, true);
// Open the input file
FileInputStream in = new FileInputStream(src);
// Transfer bytes from the input file to the GZIP output stream
byte[] buf = new byte[10240];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
// Complete the GZIP file
out.finish();
out.close();
src.delete();
return new File(outFilename);
}
示例3: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
* 数据压缩
*
* @param is
* @param os
* @throws Exception
*/
public static void compress(InputStream is, OutputStream os)
throws Exception {
GZIPOutputStream gos = new GZIPOutputStream(os);
int count;
byte data[] = new byte[BUFFER];
while ((count = is.read(data, 0, BUFFER)) != -1) {
gos.write(data, 0, count);
}
gos.finish();
gos.flush();
gos.close();
}
示例4: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static final byte[] compress(byte[] bytes)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
GZIPOutputStream gzip = new GZIPOutputStream(baos);
gzip.write(bytes, 0, bytes.length);
gzip.finish();
byte[] fewerBytes = baos.toByteArray();
gzip.close();
baos.close();
gzip = null;
baos = null;
return fewerBytes;
}
catch (IOException e)
{
throw new FacesException(e);
}
}
示例5: gzipIt
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static void gzipIt(File sourceFile) throws IOException {
// modified from: http://www.mkyong.com/java/how-to-compress-a-file-in-gzip-format/
byte[] buffer = new byte[1024];
GZIPOutputStream gzos =
new GZIPOutputStream(new FileOutputStream(sourceFile.getPath() + ".gz"));
FileInputStream in =
new FileInputStream(sourceFile);
int len;
while ((len = in.read(buffer)) > 0) {
gzos.write(buffer, 0, len);
}
in.close();
gzos.finish();
gzos.close();
}
示例6: gZip
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] gZip(byte[] data) {
byte[] b = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(bos);
gzip.write(data);
gzip.finish();
gzip.close();
b = bos.toByteArray();
bos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return b;
}
示例7: uploadGZFile
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private static void uploadGZFile(PrintStream os, File f) throws IOException {
GZIPOutputStream gzip = new GZIPOutputStream(os);
try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(f))) {
byte[] buffer = new byte[4096];
int readLength = is.read(buffer);
while (readLength != -1){
gzip.write(buffer, 0, readLength);
readLength = is.read(buffer);
}
} finally {
gzip.finish();
}
}
示例8: sendBodyWithCorrectEncoding
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private void sendBodyWithCorrectEncoding(OutputStream outputStream, long pending) throws IOException {
if (encodeAsGzip) {
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
sendBody(gzipOutputStream, -1);
gzipOutputStream.finish();
} else {
sendBody(outputStream, pending);
}
}
示例9: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] compress(byte[] data) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(baos);// 压缩
gos.write(data, 0, data.length);
gos.finish();
byte[] output = baos.toByteArray();
baos.flush();
baos.close();
return output;
}
示例10: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
* Compresses file from given filePath into a gzipPath
*
* @param filePath The file to be compressed
* @param gzipPath The path to compress to (.gz)
* @return The result
*/
public static boolean compress(Path filePath, Path gzipPath) {
byte[] buffer = new byte[1024];
try {
FileOutputStream fos = new FileOutputStream(gzipPath.toString());
GZIPOutputStream gzos = new GZIPOutputStream(fos);
FileInputStream in = new FileInputStream(filePath.toString());
int len;
while((len = in.read(buffer)) > 0){
gzos.write(buffer, 0, len);
}
in.close();
gzos.finish();
gzos.close();
fos.close();
return true;
}
catch(IOException ex) {
System.err.println("Exception while compressing '" + filePath.toString() + "':");
ex.printStackTrace();
}
return false;
}
示例11: compress
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
* 数据压缩
* @param is
* @param os
* @throws Exception
*/
public static void compress(InputStream is, OutputStream os) throws Exception {
GZIPOutputStream gos = new GZIPOutputStream(os);
int count;
byte data[] = new byte[BUFFER];
while ((count = is.read(data, 0, BUFFER)) != -1) {
gos.write(data, 0, count);
}
gos.finish();
gos.flush();
gos.close();
}
示例12: write
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public void write(OutputStream out) throws IOException {
// TEMP: just use the object output for now. We can find a more efficient storage format later
GZIPOutputStream gzipout = new GZIPOutputStream(out);
ObjectOutputStream oout = new ObjectOutputStream(gzipout);
oout.writeObject(this);
gzipout.finish();
}
示例13: write
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public void write(OutputStream out)
throws IOException {
GZIPOutputStream gzipout = new GZIPOutputStream(out);
ObjectOutputStream oout = new ObjectOutputStream(gzipout);
oout.writeObject(m_superclasses);
oout.writeObject(m_fieldEntries);
oout.writeObject(m_behaviorEntries);
gzipout.finish();
}
示例14: afterResponse
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline) throws Exception {
if (isMatch) {
try {
contentBuf.writeBytes(httpContent.content());
if (httpContent instanceof LastHttpContent) {
ByteUtil.insertText(contentBuf,ByteUtil.findText(contentBuf,"<head>"),hookResponse());
HttpContent hookHttpContent = new DefaultLastHttpContent();
if (isGzip) { //转化成gzip编码
byte[] temp = new byte[contentBuf.readableBytes()];
contentBuf.readBytes(temp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream outputStream = new GZIPOutputStream(baos);
outputStream.write(temp);
outputStream.finish();
hookHttpContent.content().writeBytes(baos.toByteArray());
} else {
hookHttpContent.content().writeBytes(contentBuf);
}
pipeline.getDefault()
.afterResponse(clientChannel, proxyChannel, hookHttpContent, pipeline);
}
} finally {
ReferenceCountUtil.release(httpContent);
}
} else {
pipeline.afterResponse(clientChannel, proxyChannel, httpContent);
}
}
示例15: doTest
import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private static void doTest(final boolean appendGarbage,
final boolean limitGISBuff)
throws Throwable {
byte[] buf;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos)) {
final byte[] xbuf = { 'x' };
zos.putNextEntry(new ZipEntry("a.gz"));
GZIPOutputStream gos1 = new GZIPOutputStream(zos);
gos1.write(xbuf);
gos1.finish();
if (appendGarbage)
zos.write(xbuf);
zos.closeEntry();
zos.putNextEntry(new ZipEntry("b.gz"));
GZIPOutputStream gos2 = new GZIPOutputStream(zos);
gos2.write(xbuf);
gos2.finish();
zos.closeEntry();
zos.flush();
buf = baos.toByteArray();
}
try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
ZipInputStream zis = new ZipInputStream(bais)) {
zis.getNextEntry();
GZIPInputStream gis1 = limitGISBuff ?
new GZIPInputStream(zis, 4) :
new GZIPInputStream(zis);
// try to read more than the entry has
gis1.skip(2);
try {
zis.getNextEntry();
} catch (IOException e) {
throw new RuntimeException("ZIP stream was prematurely closed", e);
}
}
}