当前位置: 首页>>代码示例>>Java>>正文


Java GzipCompressorInputStream类代码示例

本文整理汇总了Java中org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream的典型用法代码示例。如果您正苦于以下问题:Java GzipCompressorInputStream类的具体用法?Java GzipCompressorInputStream怎么用?Java GzipCompressorInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GzipCompressorInputStream类属于org.apache.commons.compress.compressors.gzip包,在下文中一共展示了GzipCompressorInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractTar

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
private static void extractTar(String dataIn, String dataOut) throws IOException {

        try (TarArchiveInputStream inStream = new TarArchiveInputStream(
                new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(dataIn))))) {
            TarArchiveEntry tarFile;
            while ((tarFile = (TarArchiveEntry) inStream.getNextEntry()) != null) {
                if (tarFile.isDirectory()) {
                    new File(dataOut + tarFile.getName()).mkdirs();
                } else {
                    int count;
                    byte data[] = new byte[BUFFER_SIZE];

                    FileOutputStream fileInStream = new FileOutputStream(dataOut + tarFile.getName());
                    BufferedOutputStream outStream=  new BufferedOutputStream(fileInStream, BUFFER_SIZE);
                    while ((count = inStream.read(data, 0, BUFFER_SIZE)) != -1) {
                        outStream.write(data, 0, count);
                    }
                }
            }
        }
    }
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:22,代码来源:DL4JSentimentAnalysisExample.java

示例2: addTarGzipToArchive

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
/**
 * given tar.gz file will be copied to this tar.gz file.
 * all files will be transferred to new tar.gz file one by one.
 * original directory structure will be kept intact
 *
 * @param tarGzipFile the archive file to be copied to the new archive
 */
public boolean addTarGzipToArchive(String tarGzipFile) {
  try {
    // construct input stream
    InputStream fin = Files.newInputStream(Paths.get(tarGzipFile));
    BufferedInputStream in = new BufferedInputStream(fin);
    GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
    TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzIn);

    // copy the existing entries from source gzip file
    ArchiveEntry nextEntry;
    while ((nextEntry = tarInputStream.getNextEntry()) != null) {
      tarOutputStream.putArchiveEntry(nextEntry);
      IOUtils.copy(tarInputStream, tarOutputStream);
      tarOutputStream.closeArchiveEntry();
    }

    tarInputStream.close();
    return true;
  } catch (IOException ioe) {
    LOG.log(Level.SEVERE, "Archive File can not be added: " + tarGzipFile, ioe);
    return false;
  }
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:31,代码来源:TarGzipPacker.java

示例3: getFile

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
public int getFile(SFTPTransfer sftpTransfer, StroomZipOutputStream stroomZipOutputStream, HeaderMapPopulator headerMapPopulator, SFTPFileDetails remoteFile,
		int count) throws IOException, SftpException {

	HeaderMap headerMap = new HeaderMap();
	headerMap.put(StroomAgentCollectConstants.HEADER_ARG_REMOTE_FILE,
			remoteFile.getPath());
	headerMapPopulator.populateHeaderMap(headerMap);		

	// The true flag allows for nested files
	GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream(
			sftpTransfer.getRemoteStream(remoteFile), true);

	OutputStream metaStream = stroomZipOutputStream.addEntry(new StroomZipEntry(
			null, "extract" + count, StroomZipFileType.Meta));
	headerMap.write(metaStream, true);

	OutputStream dataStream = stroomZipOutputStream.addEntry(new StroomZipEntry(
			null, "extract" + count, StroomZipFileType.Data));

	StreamUtil.streamToStream(gzipInputStream, dataStream, true);

	count++;

	return count;

}
 
开发者ID:gchq,项目名称:stroom-agent,代码行数:27,代码来源:SFTPGetHandlerCommonsCompressGZIP.java

示例4: assertEntry

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
private static void assertEntry(File file, String name) {
    boolean exist = false;

    try (TarArchiveInputStream tar = new TarArchiveInputStream(
            new GzipCompressorInputStream(
                            new FileInputStream(file)))) {


        ArchiveEntry entry;
        while ((entry = tar.getNextEntry()) != null) {
            if (entry.getName().equals(name)) {
                exist = true;
                break;
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

    if (!exist) {
        fail("zip entry " + name + " not exist!");
    }

}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:27,代码来源:WorkspaceTest.java

示例5: StashSplitIterator

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
StashSplitIterator(AmazonS3 s3, String bucket, String key) {
    InputStream rawIn = new RestartingS3InputStream(s3, bucket, key);
    try {
        // File is gzipped
        // Note:
        //   Because the content may be concatenated gzip files we cannot use the default GZIPInputStream.
        //   GzipCompressorInputStream supports concatenated gzip files.
        GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(rawIn, true);
        _in = new BufferedReader(new InputStreamReader(gzipIn, Charsets.UTF_8));
        // Create a line reader
        _reader = new LineReader(_in);
    } catch (Exception e) {
        try {
            Closeables.close(rawIn, true);
        } catch (IOException ignore) {
            // Won't happen, already caught and logged
        }
        throw Throwables.propagate(e);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:21,代码来源:StashSplitIterator.java

示例6: unTgz

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
private static List<String> unTgz(File tarFile, File directory) throws IOException {
  List<String> result = new ArrayList<>();
  try (TarArchiveInputStream in = new TarArchiveInputStream(
          new GzipCompressorInputStream(new FileInputStream(tarFile)))) {
    TarArchiveEntry entry = in.getNextTarEntry();
    while (entry != null) {
      if (entry.isDirectory()) {
        entry = in.getNextTarEntry();
        continue;
      }
      File curfile = new File(directory, entry.getName());
      File parent = curfile.getParentFile();
      if (!parent.exists()) {
        parent.mkdirs();
      }
      try (OutputStream out = new FileOutputStream(curfile)) {
        IOUtils.copy(in, out);
      }
      result.add(entry.getName());
      entry = in.getNextTarEntry();
    }
  }
  return result;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:25,代码来源:HeliumBundleFactory.java

示例7: openCompressedStream

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
/**
 * open a compressed InputStream
 * @param in the InputStream to decompress
 * @return the InputStream to read from
 * @throws IOException if an I/O error occurs
 */
private InputStream openCompressedStream(InputStream in) throws IOException {
  if(mCurrentTask.compression==null)
    return in;
  switch(mCurrentTask.compression) {
    default:
    case none:
      return in;
    case gzip:
      return new GzipCompressorInputStream(in);
    case bzip:
      return new BZip2CompressorInputStream(in);
    case xz:
      return new XZCompressorInputStream(in);
  }
}
 
开发者ID:Android-leak,项目名称:csploit,代码行数:22,代码来源:UpdateService.java

示例8: returnArchiveInputStream

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
/**
 * return archive input stream
 *
 * @param inputStream - file  input Stream
 * @param archiveSuffix   - archive suffix
 * @return archive input stream
 * @throws IOException
 */
public static ArchiveInputStream returnArchiveInputStream(InputStream inputStream, String archiveSuffix)
        throws IOException {
    if (isZipFamilyArchive(archiveSuffix)) {
        return new ZipArchiveInputStream(inputStream);
    }

    if (isTarArchive(archiveSuffix)) {
        return new TarArchiveInputStream(inputStream);
    }

    if (isTgzFamilyArchive(archiveSuffix) || isGzCompress(archiveSuffix)) {
        return new TarArchiveInputStream(new GzipCompressorInputStream(inputStream));
    }
    return null;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:24,代码来源:ZipUtils.java

示例9: extract

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
static void extract(InputStream in, Path destination) throws IOException {
  try (
      final BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
      final GzipCompressorInputStream gzipInputStream =
          new GzipCompressorInputStream(bufferedInputStream);
      final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)
  ) {
    final String destinationAbsolutePath = destination.toFile().getAbsolutePath();

    TarArchiveEntry entry;
    while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
      if (entry.isDirectory()) {
        File f = Paths.get(destinationAbsolutePath, entry.getName()).toFile();
        f.mkdirs();
      } else {
        Path fileDestinationPath = Paths.get(destinationAbsolutePath, entry.getName());

        Files.copy(tarInputStream, fileDestinationPath, StandardCopyOption.REPLACE_EXISTING);
      }
    }
  }
}
 
开发者ID:twitter,项目名称:heron,代码行数:23,代码来源:Extractor.java

示例10: checkGZipInputStream

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
protected void checkGZipInputStream() throws IOException {

		// check whether file is gz type
		if (getExtension().equals("gz") || getExtension().equals("tgz")) {
			logger.info("File extension is " + getExtension() + ", creating GzipCompressorInputStream...");
			logger.debug(new FileUtils().getFileName(downloadUrl.toString(), httpDisposition));
			httpConn = (HttpURLConnection) downloadUrl.openConnection();
			inputStream = new GzipCompressorInputStream(new BufferedInputStream(httpConn.getInputStream()), true);
			setFileName(getFileName().replace(".gz", ""));
			setFileName(getFileName().replace(".tgz", ".tar"));
			if (getFileName().contains(".tar"))
				setExtension("tar");
			if (getExtension().equals("tgz"))
				setExtension("tar");
			else
				setExtension(null);

			logger.info("Done creating GzipCompressorInputStream! New file name is " + getFileName() + ", extension: "
					+ getExtension());
		}
	}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:22,代码来源:SuperStream.java

示例11: getHeader

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
public byte[] getHeader() {
	try {
		TarArchiveEntry entry=null;
		TarArchiveInputStream tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(sinfile)));
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		while ((entry = tarIn.getNextTarEntry()) != null) {
			if (entry.getName().endsWith("cms")) {
				IOUtils.copy(tarIn, bout);
				break;
			}
		}
		tarIn.close();
		return bout.toByteArray();
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:18,代码来源:SinParser.java

示例12: dumpImage

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
public void dumpImage() {
	try {
		TarArchiveEntry entry=null;
		TarArchiveInputStream tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(sinfile)));
		FileOutputStream fout = new FileOutputStream(new File("D:\\test.ext4"));
		while ((entry = tarIn.getNextTarEntry()) != null) {
			if (!entry.getName().endsWith("cms")) {
				IOUtils.copy(tarIn, fout);
			}
		}
		tarIn.close();
		fout.flush();
		fout.close();
		logger.info("Extraction finished to "+"D:\\test.ext4");
	} catch (Exception e) {}		
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:17,代码来源:SinParser.java

示例13: deflateGz

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
public void deflateGz(Path input) {
    File tempFile;
    tempFile = new File(getDeflatedFile(input).toUri());

    try (
            InputStream fin = Files.newInputStream(input);
            BufferedInputStream in = new BufferedInputStream(fin);
            GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
            FileOutputStream out = new FileOutputStream(tempFile)) {

        final byte[] buffer = new byte[4096];
        int n;
        while (-1 != (n = gzIn.read(buffer))) {
            out.write(buffer, 0, n);
        }

    } catch (IOException e) {
        LOG.warn("[{} - {}]: Error extracting gzip  {}.", request.getLogName(), request.getId(), e.getMessage());

        throw new IllegalStateException(e);
    }
}
 
开发者ID:msoute,项目名称:vertx-deploy-tools,代码行数:23,代码来源:GzipExtractor.java

示例14: unGzip

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
/** Unpackages single file content that has been had gzip applied. */
public static byte[] unGzip(byte[] content) throws IOException {
    try (
            ByteArrayInputStream compressedIn = new ByteArrayInputStream(content);
            GzipCompressorInputStream uncompressedIn = new GzipCompressorInputStream(compressedIn);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ) {
        final byte[] buffer = new byte[8192];
        int n;
        while ((n = uncompressedIn.read(buffer)) != -1) {
            out.write(buffer, 0, n);
        }

        byte[] uncompressed = out.toByteArray();
        return uncompressed;
    }
}
 
开发者ID:stucco,项目名称:collectors,代码行数:18,代码来源:UnpackUtils.java

示例15: uncompressGzippedArcFile

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; //导入依赖的package包/类
private File uncompressGzippedArcFile(File f) throws IOException {
	FileInputStream fin = new FileInputStream(f.getAbsolutePath());
	BufferedInputStream in = new BufferedInputStream(fin);
	File uncompressedFile = new File(FilenameUtils.removeExtension(f
			.getAbsolutePath()));
	FileOutputStream out = new FileOutputStream(uncompressedFile);
	GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in, true);
	final byte[] buffer = new byte[1024];
	int n = 0;
	while (-1 != (n = gzIn.read(buffer))) {
		out.write(buffer, 0, n);
	}
	out.close();
	gzIn.close();
	return uncompressedFile;
}
 
开发者ID:lablita,项目名称:ridire-cpi,代码行数:17,代码来源:Mapper.java


注:本文中的org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。