java.util.zip.GZIPOutputStream.close()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.util.zip.GZIPOutputStream.close()方法的一些代码示例,展示了GZIPOutputStream.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GZIPOutputStream.close()方法的具体详情如下:
包路径:java.util.zip.GZIPOutputStream
类名称:GZIPOutputStream
方法名:close

GZIPOutputStream.close介绍

暂无

代码示例

代码示例来源:origin: apache/storm

public static byte[] gzip(byte[] data) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream out = new GZIPOutputStream(bos);
    out.write(data);
    out.close();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: cSploit/android

public static String saveSession(String sessionName) throws IOException {
 StringBuilder builder = new StringBuilder();
 String filename = mStoragePath + '/' + sessionName + ".dss",
     session;
 builder.append(SESSION_MAGIC + "\n");
 // skip the network target
 synchronized (mTargets) {
  builder.append(mTargets.size() - 1).append("\n");
  for (Target target : mTargets) {
   if (target.getType() != Target.Type.NETWORK)
    target.serialize(builder);
  }
 }
 session = builder.toString();
 FileOutputStream ostream = new FileOutputStream(filename);
 GZIPOutputStream gzip = new GZIPOutputStream(ostream);
 gzip.write(session.getBytes());
 gzip.close();
 mSessionName = sessionName;
 return filename;
}

代码示例来源:origin: syncany/syncany

private byte[] getPlaintextStorageXml() throws Exception {
    ByteArrayOutputStream plaintextByteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream plaintextOutputStream = new DataOutputStream(plaintextByteArrayOutputStream);
    plaintextOutputStream.writeInt(transferSettings.getType().getBytes().length);
    plaintextOutputStream.write(transferSettings.getType().getBytes());

    GZIPOutputStream plaintextGzipOutputStream = new GZIPOutputStream(plaintextOutputStream);
    new Persister(new Format(0)).write(transferSettings, plaintextGzipOutputStream);
    plaintextGzipOutputStream.close();

    return plaintextByteArrayOutputStream.toByteArray();
  }
}

代码示例来源:origin: prometheus/client_java

public void handle(HttpExchange t) throws IOException {
  String query = t.getRequestURI().getRawQuery();
  ByteArrayOutputStream response = this.response.get();
  response.reset();
  OutputStreamWriter osw = new OutputStreamWriter(response);
  TextFormat.write004(osw,
      registry.filteredMetricFamilySamples(parseQuery(query)));
  osw.flush();
  osw.close();
  response.flush();
  response.close();
  t.getResponseHeaders().set("Content-Type",
      TextFormat.CONTENT_TYPE_004);
  if (shouldUseCompression(t)) {
    t.getResponseHeaders().set("Content-Encoding", "gzip");
    t.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
    final GZIPOutputStream os = new GZIPOutputStream(t.getResponseBody());
    response.writeTo(os);
    os.close();
  } else {
    t.getResponseHeaders().set("Content-Length",
        String.valueOf(response.size()));
    t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.size());
    response.writeTo(t.getResponseBody());
  }
  t.close();
}

代码示例来源:origin: alibaba/nacos

private static byte[] compressIfNecessary(byte[] dataBytes) throws IOException {
  // enable compression when data is larger than 1KB
  int maxDataSizeUncompress = 1024;
  if (dataBytes.length < maxDataSizeUncompress) {
    return dataBytes;
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  GZIPOutputStream gzip = new GZIPOutputStream(out);
  gzip.write(dataBytes);
  gzip.close();
  return out.toByteArray();
}

代码示例来源:origin: kairosdb/kairosdb

/**
 Compresses the given file and removes the uncompressed file
 @param file name of the zip file
 @return Size of the zip file
 */
private long zipFile(String file) throws IOException
{
  cleanDiskSpace();
  if (hasSpace())
  {
    String zipFile = file + ".gz";
    FileInputStream is = new FileInputStream(file);
    GZIPOutputStream gout = new GZIPOutputStream(new FileOutputStream(zipFile));
    byte[] buffer = new byte[1024];
    int readSize;
    while ((readSize = is.read(buffer)) != -1)
      gout.write(buffer, 0, readSize);
    is.close();
    gout.flush();
    gout.close();
    //delete uncompressed file
    new File(file).delete();
    return (new File(zipFile).length());
  }
  else
  {
    logger.error("No space available to create zip files after attempting clean up");
    return 0;
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

File tempFile = File.createTempFile(pointSetId, ".json.gz");
FileOutputStream fos = new FileOutputStream(tempFile);
GZIPOutputStream gos = new GZIPOutputStream(fos);
  gos.close();
  fis.close();

代码示例来源:origin: lets-blade/blade

public static byte[] compressGZIPAsString(String content, Charset charset) throws IOException {
  if (content == null || content.length() == 0) {
    return null;
  }
  GZIPOutputStream      gzip;
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  gzip = new GZIPOutputStream(out);
  gzip.write(content.getBytes(charset));
  gzip.close();
  return out.toByteArray();
}

代码示例来源:origin: cSploit/android

public String save(String sessionName) throws IOException {
 StringBuilder builder = new StringBuilder();
 String filename = System.getStoragePath() + '/' + sessionName + ".dhs",
     buffer = null;
 builder.append( System.SESSION_MAGIC + "\n");
 builder.append(mUserName == null ? "null" : mUserName).append("\n");
 builder.append(mHTTPS).append("\n");
 builder.append(mAddress).append("\n");
 builder.append(mDomain).append("\n");
 builder.append(mUserAgent).append("\n");
 builder.append(mCookies.size()).append("\n");
 for(HttpCookie cookie : mCookies.values()){
  builder
   .append(cookie.getName()).append( "=" ).append(cookie.getValue())
   .append( "; domain=").append(cookie.getDomain())
   .append( "; path=/" )
   .append( mHTTPS ? ";secure" : "" )
   .append("\n");
 }
 buffer = builder.toString();
 FileOutputStream ostream = new FileOutputStream(filename);
 GZIPOutputStream gzip = new GZIPOutputStream(ostream);
 gzip.write(buffer.getBytes());
 gzip.close();
 return filename;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void processDynamic(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
  ContentCachingResponseWrapper wrapper = new ContentCachingResponseWrapper(response);
  chain.doFilter(request, wrapper);
  FastByteArrayOutputStream baos = new FastByteArrayOutputStream(1024);
  GZIPOutputStream zip = new GZIPOutputStream(baos);
  StreamUtils.copy(wrapper.getContentInputStream(), zip);
  zip.close();
  response.addHeader("Content-Encoding", "gzip");
  response.setContentLength(baos.size());
  StreamUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
}

代码示例来源:origin: lets-blade/blade

public static byte[] compressGZIPAsString(String content, Charset charset) throws IOException {
  if (content == null || content.length() == 0) {
    return null;
  }
  GZIPOutputStream      gzip;
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  gzip = new GZIPOutputStream(out);
  gzip.write(content.getBytes(charset));
  gzip.close();
  return out.toByteArray();
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 *
 * @param fileWorkArea
 * @param fileNames
 */
protected void gzipAndDeleteFiles(FileWorkArea fileWorkArea, List<String> fileNames,boolean shouldDeleteOriginal){
  for (String fileName : fileNames) {
    try {
      String fileNameWithPath = FilenameUtils.normalize(fileWorkArea.getFilePathLocation() + File.separator + fileName);
      FileInputStream fis = new FileInputStream(fileNameWithPath);
      FileOutputStream fos = new FileOutputStream(fileNameWithPath + ENCODING_EXTENSION);
      GZIPOutputStream gzipOS = new GZIPOutputStream(fos);
      byte[] buffer = new byte[1024];
      int len;
      while ((len = fis.read(buffer)) != -1) {
        gzipOS.write(buffer, 0, len);
      }
      //close resources
      gzipOS.close();
      fos.close();
      fis.close();
      if(shouldDeleteOriginal){
        File originalFile = new File(fileNameWithPath);
        originalFile.delete();
      }
    } catch (IOException e) {
      LOG.error("Error writing zip file.", e);
    }
  }
}

代码示例来源:origin: GoogleContainerTools/jib

GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream);
DescriptorDigest layerDiffId = uncompressedLayerBlob.writeTo(compressorStream).getDigest();
compressorStream.close();
BlobDescriptor compressedBlobDescriptor = compressedDigestOutputStream.toBlobDescriptor();
DescriptorDigest layerDigest = compressedBlobDescriptor.getDigest();

代码示例来源:origin: alibaba/jstorm

public static byte[] gzip(byte[] data) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream out = new GZIPOutputStream(bos);
    out.write(data);
    out.close();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: Qihoo360/XLearning

OutputStreamWriter osw = new OutputStreamWriter(xlearningProcess.getOutputStream());
 File gzFile = new File(conf.get(XLearningConfiguration.XLEARNING_INPUTFORMAT_CACHEFILE_NAME, XLearningConfiguration.DEFAULT_XLEARNING_INPUTFORMAT_CACHEFILE_NAME));
 GZIPOutputStream gos = new GZIPOutputStream(new FileOutputStream(gzFile));
 boolean isCache = conf.getBoolean(XLearningConfiguration.XLEARNING_INPUTFORMAT_CACHE, XLearningConfiguration.DEFAULT_XLEARNING_INPUTFORMAT_CACHE);
 List<InputSplit> inputs = Arrays.asList(amClient.getStreamInputSplit(containerId));
     if (j == 0 && isCache) {
      if (conf.getInt(XLearningConfiguration.XLEARNING_STREAM_EPOCH, XLearningConfiguration.DEFAULT_XLEARNING_STREAM_EPOCH) > 1) {
       gos.write(value.toString().getBytes());
       gos.write("\n".getBytes());
 gos.close();
} catch (Exception e) {
 LOG.warn("Exception in thread stdinRedirectThread");

代码示例来源:origin: weibocom/motan

public static byte[] gzip(byte[] data) throws IOException {
  ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
  GZIPOutputStream gzip = null;
  try {
    gzip = new GZIPOutputStream(bos);
    gzip.write(data);
    gzip.finish();
    return bos.toByteArray();
  } finally {
    if (gzip != null) {
      gzip.close();
    }
  }
}

代码示例来源:origin: ankidroid/Anki-Android

byte[] chunk = new byte[65536];
if (comp != 0) {
  tgt = new GZIPOutputStream(bos);
  while ((len = bfobj.read(chunk)) >= 0) {
    tgt.write(chunk, 0, len);
  tgt.close();
  bos = new BufferedOutputStream(new FileOutputStream(tmpFileBuffer, true));
} else {

代码示例来源:origin: weibocom/motan

public byte[] compress(byte[] org, boolean useGzip, int minGzSize) throws IOException {
  if (useGzip && org.length > minGzSize) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(outputStream);
    gos.write(org);
    gos.finish();
    gos.flush();
    gos.close();
    byte[] ret = outputStream.toByteArray();
    return ret;
  } else {
    return org;
  }
}

代码示例来源:origin: SonarSource/sonarqube

GZIPOutputStream gzipOutputStream = new GZIPOutputStream(resp.getOutputStream());
 gzipOutputStream.write("GZIP response".getBytes());
 gzipOutputStream.close();
} else {
 resp.getPrintStream().append("agent=" + req.getValues("User-Agent").get(0));

代码示例来源:origin: azkaban/azkaban

public static byte[] gzipBytes(final byte[] bytes, final int offset, final int length)
  throws IOException {
 final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
 GZIPOutputStream gzipStream = null;
 gzipStream = new GZIPOutputStream(byteOutputStream);
 gzipStream.write(bytes, offset, length);
 gzipStream.close();
 return byteOutputStream.toByteArray();
}

相关文章