當前位置: 首頁>>代碼示例>>Java>>正文


Java TarArchiveInputStream.getNextTarEntry方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry方法的典型用法代碼示例。如果您正苦於以下問題:Java TarArchiveInputStream.getNextTarEntry方法的具體用法?Java TarArchiveInputStream.getNextTarEntry怎麽用?Java TarArchiveInputStream.getNextTarEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.tar.TarArchiveInputStream的用法示例。


在下文中一共展示了TarArchiveInputStream.getNextTarEntry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: untar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void untar(InputStream in, File targetDir) throws IOException {
  final TarArchiveInputStream tarIn = new TarArchiveInputStream(in);
  byte[] b = new byte[BUF_SIZE];
  TarArchiveEntry tarEntry;
  while ((tarEntry = tarIn.getNextTarEntry()) != null) {
    final File file = new File(targetDir, tarEntry.getName());
    if (tarEntry.isDirectory()) {
      if (!file.mkdirs()) {
        throw new IOException("Unable to create folder " + file.getAbsolutePath());
      }
    } else {
      final File parent = file.getParentFile();
      if (!parent.exists()) {
        if (!parent.mkdirs()) {
          throw new IOException("Unable to create folder " + parent.getAbsolutePath());
        }
      }
      try (FileOutputStream fos = new FileOutputStream(file)) {
        int r;
        while ((r = tarIn.read(b)) != -1) {
          fos.write(b, 0, r);
        }
      }
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:TarUtils.java

示例2: verifyTarArchive

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Helper method to verify that the files were archived correctly by reading {@code
 * tarArchiveInputStream}.
 */
private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throws IOException {
  // Verifies fileA was archived correctly.
  TarArchiveEntry headerFileA = tarArchiveInputStream.getNextTarEntry();
  Assert.assertEquals("some/path/to/resourceFileA", headerFileA.getName());
  String fileAString =
      CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
  Assert.assertEquals(expectedFileAString, fileAString);

  // Verifies fileB was archived correctly.
  TarArchiveEntry headerFileB = tarArchiveInputStream.getNextTarEntry();
  Assert.assertEquals("crepecake", headerFileB.getName());
  String fileBString =
      CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
  Assert.assertEquals(expectedFileBString, fileBString);

  // Verifies directoryA was archived correctly.
  TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry();
  Assert.assertEquals("some/path/to/", headerDirectoryA.getName());

  Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:26,代碼來源:TarStreamBuilderTest.java

示例3: dearchive

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * 文件 解歸檔
 *
 * @param destFile
 *            目標文件
 * @param tais
 *            ZipInputStream
 * @throws Exception
 */
private static void dearchive(File destFile, TarArchiveInputStream tais)
        throws Exception {

    TarArchiveEntry entry = null;
    while ((entry = tais.getNextTarEntry()) != null) {

        // 文件
        String dir = destFile.getPath() + File.separator + entry.getName();

        File dirFile = new File(dir);

        // 文件檢查
        fileProber(dirFile);

        if (entry.isDirectory()) {
            dirFile.mkdirs();
        } else {
            dearchiveFile(dirFile, tais);
        }

    }
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:32,代碼來源:TarUtils.java

示例4: run

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
@Override
public void run(Parameters p, PrintStream output) throws Exception {
  TarArchiveInputStream tais = new TarArchiveInputStream(StreamCreator.openInputStream(p.getString("input")));
  ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(p.getString("output")));
  boolean quiet = p.get("quiet", false);

  while(true) {
    TarArchiveEntry tarEntry = tais.getNextTarEntry();
    if(tarEntry == null) break;
    if(!tarEntry.isFile()) continue;
    if(!tais.canReadEntryData(tarEntry)) continue;

    if(!quiet) System.err.println("# "+tarEntry.getName());

    ZipEntry forData = new ZipEntry(tarEntry.getName());
    forData.setSize(tarEntry.getSize());
    zos.putNextEntry(forData);
    StreamUtil.copyStream(tais, zos);
    zos.closeEntry();
  }
  tais.close();
  zos.close();
}
 
開發者ID:teanalab,項目名稱:demidovii,代碼行數:24,代碼來源:TarToZipConverter.java

示例5: untarFile

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void untarFile(File file) throws IOException {
    FileInputStream fileInputStream = null;
    String currentDir = file.getParent();
    try {
        fileInputStream = new FileInputStream(file);
        GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
        TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipInputStream);

        TarArchiveEntry tarArchiveEntry;

        while (null != (tarArchiveEntry = tarArchiveInputStream.getNextTarEntry())) {
            if (tarArchiveEntry.isDirectory()) {
                FileUtils.forceMkdir(new File(currentDir + File.separator + tarArchiveEntry.getName()));
            } else {
                byte[] content = new byte[(int) tarArchiveEntry.getSize()];
                int offset = 0;
                tarArchiveInputStream.read(content, offset, content.length - offset);
                FileOutputStream outputFile = new FileOutputStream(currentDir + File.separator + tarArchiveEntry.getName());
                org.apache.commons.io.IOUtils.write(content, outputFile);
                outputFile.close();
            }
        }
    } catch (FileNotFoundException e) {
        throw new IOException(e.getStackTrace().toString());
    }
}
 
開發者ID:foundation-runtime,項目名稱:jenkins-openstack-deployment-plugin,代碼行數:27,代碼來源:CompressUtils.java

示例6: findLastTarEntry

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private InputStream findLastTarEntry() throws IOException {
    SeekableXZInputStream stream = (SeekableXZInputStream)xz.stream();
    
    stream.seekToBlock(stream.getBlockCount() - 2);
    byte[] buffer = new byte[(int)(stream.length() - stream.position())];
    IOUtils.readFully(stream, buffer);
    ByteArrayInputStream memoryStream = new ByteArrayInputStream(buffer);        
    
    TarArchiveInputStream tar = new TarArchiveInputStream(memoryStream);
    for (int i = 0; i < (buffer.length / TarConstants.DEFAULT_RCDSIZE); i++) {
        TarArchiveEntry entry = null;

        memoryStream.reset();
        memoryStream.skip(i * TarConstants.DEFAULT_RCDSIZE);
        tar.reset();
        try {
            entry = tar.getNextTarEntry();
        } catch (IOException ex) {
        }
        if (entry != null && entry.getName().equals(FOOTER_NAME)) {
            return tar;
        }
    }
    throw new IOException("Invalid file format");
}
 
開發者ID:cody271,項目名稱:jaywixz,代碼行數:26,代碼來源:ArchiveFile.java

示例7: parse

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
@Override
public void parse(File file) throws IOException {
    mEntries = new ArrayList<>();

    BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
    TarArchiveInputStream is = new TarArchiveInputStream(fis);
    TarArchiveEntry entry = is.getNextTarEntry();
    while (entry != null) {
        if (entry.isDirectory()) {
            continue;
        }
        if (Utils.isImage(entry.getName())) {
            mEntries.add(new TarEntry(entry, Utils.toByteArray(is)));
        }
        entry = is.getNextTarEntry();
    }

    Collections.sort(mEntries, new NaturalOrderComparator() {
        @Override
        public String stringValue(Object o) {
            return ((TarEntry) o).entry.getName();
        }
    });
}
 
開發者ID:nkanaev,項目名稱:bubble,代碼行數:25,代碼來源:TarParser.java

示例8: getBufferedReaderTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Gets a Reader for a file in a gzipped tarball
 * @param tarPath   Path to the tarball
 * @param fileName   File within the tarball
 * @return   The file's reader
 */
public static BufferedReader getBufferedReaderTarGz(final String tarPath, final String fileName) {
    try {
        InputStream result = null;
        final TarArchiveInputStream tarStream = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(tarPath)));
        TarArchiveEntry entry = tarStream.getNextTarEntry();
        while (entry != null) {
            if (entry.getName().equals(fileName)) {
                result = tarStream;
                break;
            }
            entry = tarStream.getNextTarEntry();
        }
        if (result == null) {
            throw new UserException.BadInput("Could not find file " + fileName + " in tarball " + tarPath);
        }
        return new BufferedReader(new InputStreamReader(result));
    } catch (final IOException e) {
        throw new UserException.BadInput("Could not open compressed tarball file " + fileName + " in " + tarPath, e);
    }
}
 
開發者ID:broadinstitute,項目名稱:gatk,代碼行數:27,代碼來源:PSBuildReferenceTaxonomyUtils.java

示例9: getHeader

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的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

示例10: dumpImage

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的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

示例11: getTransferVmdK

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private ITransferVmdkFrom getTransferVmdK(final String templateFilePathStr, final String vmdkName) throws IOException {
    final Path templateFilePath = Paths.get(templateFilePathStr);
    if (isOva(templateFilePath)) {
        final TarArchiveInputStream tar = new TarArchiveInputStream(new FileInputStream(templateFilePathStr));
        TarArchiveEntry entry;
        while ((entry = tar.getNextTarEntry()) != null) {
            if (new File(entry.getName()).getName().startsWith(vmdkName)) {
                return new TransferVmdkFromInputStream(tar, entry.getSize());
            }
        }
    } else if (isOvf(templateFilePath)) {
        final Path vmdkPath = templateFilePath.getParent().resolve(vmdkName);
        return new TransferVmdkFromFile(vmdkPath.toFile());
    }
    throw new RuntimeException(NOT_OVA_OR_OVF);
}
 
開發者ID:CloudSlang,項目名稱:cs-actions,代碼行數:17,代碼來源:DeployOvfTemplateService.java

示例12: extractFileByName

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private File extractFileByName(File archive, String filenameToExtract) throws IOException {
    File baseDir = new File(FileUtils.getTempDirectoryPath());
    File expectedFile = new File(baseDir, filenameToExtract);
    expectedFile.delete();
    assertThat(expectedFile.exists(), is(false));

    TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new GZIPInputStream(
            new BufferedInputStream(new FileInputStream(archive))));
    TarArchiveEntry entry;
    while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
        String individualFiles = entry.getName();
        // there should be only one file in this archive
        assertThat(individualFiles, equalTo("executableFile.sh"));
        IOUtils.copy(tarArchiveInputStream, new FileOutputStream(expectedFile));
        if ((entry.getMode() & 0755) == 0755) {
            expectedFile.setExecutable(true);
        }
    }
    tarArchiveInputStream.close();
    return expectedFile;
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:22,代碼來源:CompressArchiveUtilTest.java

示例13: unpackTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void unpackTar(InputStream tarArchive, File outputDirectory) throws IOException {
    TarArchiveInputStream tarStream = new TarArchiveInputStream(tarArchive);
    TarArchiveEntry entry;

    while ((entry = tarStream.getNextTarEntry()) != null) {
        unpackTarArchiveEntry(tarStream, entry, outputDirectory);
    }

}
 
開發者ID:Panda-Programming-Language,項目名稱:Pandomium,代碼行數:10,代碼來源:ArchiveUtils.java

示例14: unpack

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private void unpack(final @WillNotClose TarArchiveInputStream tain)
throws IOException {
    final TarDriver driver = this.driver;
    final IoBufferPool pool = driver.getPool();
    for (   TarArchiveEntry tinEntry;
            null != (tinEntry = tain.getNextTarEntry()); ) {
        final String name = name(tinEntry);
        TarDriverEntry entry = entries.get(name);
        if (null != entry)
            entry.release();
        entry = driver.newEntry(name, tinEntry);
        if (!tinEntry.isDirectory()) {
            final IoBuffer buffer = pool.allocate();
            entry.setBuffer(buffer);
            try {
                try (OutputStream out = buffer.output().stream(null)) {
                    Streams.cat(tain, out);
                }
            } catch (final Throwable ex) {
                try {
                    buffer.release();
                } catch (final Throwable ex2) {
                    ex.addSuppressed(ex2);
                }
                throw ex;
            }
        }
        entries.put(name, entry);
    }
}
 
開發者ID:christian-schlichtherle,項目名稱:truevfs,代碼行數:31,代碼來源:TarInputService.java

示例15: extract

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Unpack the contents of a tarball (.tar.gz)
 *
 * @param tarball The source tarbal
 */
public static void extract(File tarball) throws IOException {

  TarArchiveInputStream tarIn = new TarArchiveInputStream(
      new GzipCompressorInputStream(
          new BufferedInputStream(
              new FileInputStream(tarball))));

  TarArchiveEntry tarEntry = tarIn.getNextTarEntry();

  while (tarEntry != null) {
    File entryDestination = new File(tarball.getParent(), tarEntry.getName());
    FileUtils.forceMkdirParent(entryDestination);

    if (tarEntry.isDirectory()) {
      FileUtils.forceMkdir(entryDestination);
    } else {
      entryDestination.createNewFile();

      BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(entryDestination));
      byte[] buffer = new byte[1024];
      int len;

      while ((len = tarIn.read(buffer)) != -1) {
        outputStream.write(buffer, 0, len);
      }

      outputStream.close();
    }

    tarEntry = tarIn.getNextTarEntry();
  }

  tarIn.close();
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:40,代碼來源:TarArchiveUtils.java


注:本文中的org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。