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


Java TarArchiveInputStream.getNextEntry方法代碼示例

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


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

示例1: readFileFromContainer

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
@Nullable
private byte[] readFileFromContainer(@NonNull final DockerClient _dockerClient,
                                     @NonNull final CreateContainerResponse _container,
                                     @NonNull final String _outputFile) {
    final InputStream fileStream =_dockerClient
            .copyArchiveFromContainerCmd(_container.getId(), _outputFile)
            .exec();
    final TarArchiveInputStream tarIn = new TarArchiveInputStream(fileStream);

    try {
        if (tarIn.getNextEntry() == null) {
            log.error("No entry in tar archive");
            return null;
        }

        return IOUtils.toByteArray(tarIn);
    } catch (IOException _e) {
        log.error("Could not read file from container", _e);
        return null;
    }
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:22,代碼來源:DockerExecutorPlugin.java

示例2: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private boolean unTar(TarArchiveInputStream tarIn, String outputDir) throws IOException {
	ArchiveEntry entry;
	boolean newFile = false;
	while ((entry = tarIn.getNextEntry()) != null) {
		File tmpFile = new File(outputDir + "/" + entry.getName());
		newFile = tmpFile.createNewFile();
		OutputStream out = new FileOutputStream(tmpFile);
		int length;
		byte[] b = new byte[2048];
		while ((length = tarIn.read(b)) != -1)
			out.write(b, 0, length);
		out.close();
	}
	tarIn.close();
	return newFile;
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:17,代碼來源:DockerOperator.java

示例3: addTarGzipToArchive

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

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static List<String> untar(FileInputStream input, String targetPath) throws IOException {
    TarArchiveInputStream tarInput = new TarArchiveInputStream(input);
    ArrayList<String> result = new ArrayList<String>();

    ArchiveEntry  entry;
    while ((entry = tarInput.getNextEntry()) != null) {
        File destPath=new File(targetPath,entry.getName());
        result.add(destPath.getPath());
        if (!entry.isDirectory()) {
            FileOutputStream fout=new FileOutputStream(destPath);
            final byte[] buffer=new byte[8192];
            int n=0;
            while (-1 != (n=tarInput.read(buffer))) {
                fout.write(buffer,0,n);
            }
            fout.close();
        }
        else {
            destPath.mkdir();
        }
    }
    tarInput.close();
    return result;
}
 
開發者ID:BloomBooks,項目名稱:BloomReader,代碼行數:25,代碼來源:IOUtilities.java

示例5: untar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void untar(
        InputStream tar,
        File parentDir
) throws IOException {
    TarArchiveInputStream tin = new TarArchiveInputStream(tar);
    ArchiveEntry e;
    while ((e = tin.getNextEntry()) != null) {
        File f = new File(parentDir, e.getName());
        f.setLastModified(e.getLastModifiedDate().getTime());
        f.getParentFile().mkdirs();
        if (e.isDirectory()) {
            f.mkdir();
            continue;
        }
        long size = e.getSize();
        checkFileSize(size);
        try (OutputStream out = new FileOutputStream(f)) {
            /* TarInputStream pretends each
               entry's EOF is the stream's EOF */
            IOUtils.copy(tin, out);
        }
    }
}
 
開發者ID:winstonli,項目名稱:writelatex-git-bridge,代碼行數:24,代碼來源:Tar.java

示例6: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Untar
 * 
 * @throws IOException
 * @throws FileNotFoundException
 *
 * @return The {@link List} of {@link File}s with the untared content.
 * @throws ArchiveException
 */
public static void unTar(final InputStream is, final OutputStream outputFileStream)
		throws FileNotFoundException, IOException, ArchiveException {
	try {
		final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory()
				.createArchiveInputStream("tar", is);
		TarArchiveEntry entry = null;
		while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
			logger.debug("Entry = " + entry.getName());
			IOUtils.copy(debInputStream, outputFileStream);
		}
	} finally {
		is.close();
	}
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:24,代碼來源:FilesUtils.java

示例7: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private static List<File> unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
    Log.i(TAG, String.format("Untaring %s to dir %s", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));

    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }
    final List<File> untaredFiles = new LinkedList<File>();
    final InputStream is = new FileInputStream(inputFile);
    final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
    TarArchiveEntry entry = null;
    while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
        final File outputFile = new File(outputDir, entry.getName());
        if (entry.isDirectory()) {
            if (!outputFile.exists()) {
                if (!outputFile.mkdirs()) {
                    throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
                }
            }
        } else {
            final OutputStream outputFileStream = new FileOutputStream(outputFile);
            IOUtils.copy(debInputStream, outputFileStream);
            outputFileStream.close();
        }
        untaredFiles.add(outputFile);
    }
    debInputStream.close();

    return untaredFiles;
}
 
開發者ID:staltz,項目名稱:react-native-node,代碼行數:30,代碼來源:RNNodeService.java

示例8: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/** Untar an input file into an output file.

	 * The output file is created in the output folder, having the same name
	 * as the input file, minus the '.tar' extension. 
	 * 
	 * @param inputFile     the input .tar file
	 * @param outputDir     the output directory file. 
	 * @throws IOException 
	 * @throws FileNotFoundException
	 *  
	 * @return  The {@link List} of {@link File}s with the untared content.
	 * @throws ArchiveException 
	 */
	private List<File> unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {

	    _log.info(String.format("Untaring %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));

	    final List<File> untaredFiles = new LinkedList<File>();
	    final InputStream is = new FileInputStream(inputFile); 
	    final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
	    TarArchiveEntry entry = null; 
	    while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
	        final File outputFile = new File(outputDir, entry.getName());
	        if (entry.isDirectory()) {
	            _log.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
	            if (!outputFile.exists()) {
	                _log.info(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
	                if (!outputFile.mkdirs()) {
	                    throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
	                }
	            }
	        } else {
	            _log.info(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
	            final OutputStream outputFileStream = new FileOutputStream(outputFile); 
	            IOUtils.copy(debInputStream, outputFileStream);
	            outputFileStream.close();
	        }
	        untaredFiles.add(outputFile);
	    }
	    debInputStream.close(); 

	    return untaredFiles;
	}
 
開發者ID:OpenCompare,項目名稱:pcmdata-importers,代碼行數:44,代碼來源:OFFDumpRetriever.java

示例9: addFileToTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private void addFileToTar(File source, File file, String fileName) throws IOException, ArchiveException {
    File tmpTar = File.createTempFile(source.getName(), null, parentDir);
    tmpTar.delete();
    if (!source.renameTo(tmpTar)) {
        throw new IOException("Could not make temp file (" + source.getName() + ")");
    }

    FileInputStream fis = new FileInputStream(tmpTar);
    TarArchiveInputStream tin = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, fis);
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(source));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);

    InputStream in = new FileInputStream(file);

    // copy the existing entries    
    ArchiveEntry nextEntry;
    while ((nextEntry = tin.getNextEntry()) != null) {
        tos.putArchiveEntry(nextEntry);
        IOUtils.copy(tin, tos);
        tos.closeArchiveEntry();
    }

    // Add the new entry
    TarArchiveEntry entry = new TarArchiveEntry(fileName == null ? file.getName() : fileName);
    entry.setSize(file.length());
    tos.putArchiveEntry(entry);
    IOUtils.copy(in, tos);
    tos.closeArchiveEntry();

    IOHelper.close(fis, in, tin, tos);
    LOG.trace("Deleting temporary file: {}", tmpTar);
    FileUtil.deleteFile(tmpTar);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:35,代碼來源:TarAggregationStrategy.java

示例10: addEntryToTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private void addEntryToTar(File source, String entryName, byte[] buffer, int length) throws IOException, ArchiveException {
    File tmpTar = File.createTempFile(source.getName(), null, parentDir);
    tmpTar.delete();
    if (!source.renameTo(tmpTar)) {
        throw new IOException("Cannot create temp file: " + source.getName());
    }

    FileInputStream fis = new FileInputStream(tmpTar);
    TarArchiveInputStream tin = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, fis);
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(source));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);

    // copy the existing entries    
    ArchiveEntry nextEntry;
    while ((nextEntry = tin.getNextEntry()) != null) {
        tos.putArchiveEntry(nextEntry);
        IOUtils.copy(tin, tos);
        tos.closeArchiveEntry();
    }

    // Create new entry
    TarArchiveEntry entry = new TarArchiveEntry(entryName);
    entry.setSize(length);
    tos.putArchiveEntry(entry);
    tos.write(buffer, 0, length);
    tos.closeArchiveEntry();

    IOHelper.close(fis, tin, tos);
    LOG.trace("Deleting temporary file: {}", tmpTar);
    FileUtil.deleteFile(tmpTar);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:TarAggregationStrategy.java

示例11: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/** Untar an input file into an output file.

	 * The output file is created in the output folder, having the same name
	 * as the input file, minus the '.tar' extension. 
	 * 
	 * @param inputFile     the input .tar file
	 * @param outputDir     the output directory file. 
	 * @throws IOException 
	 * @throws FileNotFoundException
	 *  
	 * @return  The {@link List} of {@link File}s with the untared content.
	 * @throws ArchiveException 
	 */
	public static List<File> unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {

	    LOG.info(String.format("Untaring %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));

	    final List<File> untaredFiles = new LinkedList<File>();
	    final InputStream is = new FileInputStream(inputFile); 
	    final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
	    TarArchiveEntry entry = null; 
	    while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
	        final File outputFile = new File(outputDir, entry.getName());
	        if (entry.isDirectory()) {
	            LOG.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
	            if (!outputFile.exists()) {
	                LOG.info(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
	                if (!outputFile.mkdirs()) {
	                    throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
	                }
	            }
	        } else {
	            LOG.info(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
	            final OutputStream outputFileStream = new FileOutputStream(outputFile); 
	            IOUtils.copy(debInputStream, outputFileStream);
	            outputFileStream.close();
	        }
	        untaredFiles.add(outputFile);
	    }
	    debInputStream.close(); 

	    return untaredFiles;
	}
 
開發者ID:jpplayer,項目名稱:amstore-view,代碼行數:44,代碼來源:AmbariStoreHelper.java

示例12: extractTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void extractTarGz(InputStream inputTarGzStream, String outDir,
    boolean logging) {
  try {
    GzipCompressorInputStream gzIn = new GzipCompressorInputStream(
        inputTarGzStream);
    TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn);

    // read Tar entries
    TarArchiveEntry entry = null;
    while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) {
      if (logging) {
        LOG.info("Extracting: " + outDir + File.separator + entry.getName());
      }
      if (entry.isDirectory()) { // create directory
        File f = new File(outDir + File.separator + entry.getName());
        f.mkdirs();
      } else { // decompress file
        int count;
        byte data[] = new byte[EXTRACT_BUFFER_SIZE];

        FileOutputStream fos = new FileOutputStream(outDir + File.separator
            + entry.getName());
        BufferedOutputStream dest = new BufferedOutputStream(fos,
            EXTRACT_BUFFER_SIZE);
        while ((count = tarIn.read(data, 0, EXTRACT_BUFFER_SIZE)) != -1) {
          dest.write(data, 0, count);
        }
        dest.close();
      }
    }

    // close input stream
    tarIn.close();

  } catch (IOException e) {
    LOG.error("IOException: " + e.getMessage());
  }
}
 
開發者ID:millecker,項目名稱:senti-storm,代碼行數:39,代碼來源:IOUtils.java

示例13: storeOperator

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Stores an operator from a tarball
 * */
private void storeOperator(InputStream is, String outputDir) throws Exception {
	
	logger.info("Writting operator to: "+outputDir);
	
	File file = new File(outputDir);
    file.mkdir();
	
    TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
    TarArchiveEntry entry = null; 
    while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
        final File outputFile = new File(outputDir, entry.getName());
        if (entry.isDirectory()) {
        	logger.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
            if (!outputFile.exists()) {
            	logger.info(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
                if (!outputFile.mkdirs()) {
                    throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
                }
            }
        } else {
        	logger.info(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
            final OutputStream outputFileStream = new FileOutputStream(outputFile); 
            IOUtils.copy(debInputStream, outputFileStream);
            outputFileStream.close();
        }
    }

    debInputStream.close();
}
 
開發者ID:project-asap,項目名稱:IReS-Platform,代碼行數:33,代碼來源:Operators.java

示例14: processGis1

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private List<File> processGis1(InputStream is, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {

        logger.info(String.format("Untaring file to dir %s.", outputDir.getAbsolutePath()));

        final List<File> untaredFiles = new LinkedList<File>();
       // final InputStream is = new FileInputStream(inputFile); 
        final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
        TarArchiveEntry entry = null; 
        while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
            final File outputFile = new File(outputDir, entry.getName());
            if (entry.isDirectory()) {
            	logger.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
                if (!outputFile.exists()) {
                	logger.info(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
                    if (!outputFile.mkdirs()) {
                        throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
                    }
                }
            } else {
            	logger.info(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
                final OutputStream outputFileStream = new FileOutputStream(outputFile); 
                IOUtils.copy(debInputStream, outputFileStream);
                outputFileStream.close();
            }
            untaredFiles.add(outputFile);
        }
        debInputStream.close(); 

        return untaredFiles;
    }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:31,代碼來源:GISFiler.java

示例15: streamRecording

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
@SneakyThrows
public InputStream streamRecording() {
    TarArchiveInputStream archiveInputStream = new TarArchiveInputStream(
            dockerClient.copyArchiveFromContainerCmd(containerId, RECORDING_FILE_NAME).exec()
    );
    archiveInputStream.getNextEntry();
    return archiveInputStream;
}
 
開發者ID:testcontainers,項目名稱:testcontainers-java,代碼行數:9,代碼來源:VncRecordingContainer.java


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