當前位置: 首頁>>代碼示例>>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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例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;未經允許,請勿轉載。