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


Java TarArchiveEntry类代码示例

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


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

示例1: addDirectory

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
/**
 * @deprecated see {@link PLP5ProjectParser#parse(File)}
 */
private static void addDirectory(TarArchiveInputStream plpInputStream,
		TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
		throws IOException
{
	for (TarArchiveEntry subEntry : entry.getDirectoryEntries())
	{
		if (!subEntry.isDirectory())
		{
			addFile(plpInputStream, subEntry, assembleFile, projectFiles);
		}
		else
		{
			addDirectory(plpInputStream, subEntry, assembleFile, projectFiles);
		}
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:20,代码来源:FileUtil.java

示例2: addSingleEntryToTar

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
private void addSingleEntryToTar(byte[] singleEntryContent, String singleEntryName)
        throws IOException
{
    // create new entry; it requires file for some reasons...
    File tmpFile = File.createTempFile("temp", "bin");
    OutputStream os = new FileOutputStream(tmpFile);
    IOUtils.write(singleEntryContent, os);

    TarArchiveEntry tarEntry = new TarArchiveEntry(tmpFile, singleEntryName);
    outputStream.putArchiveEntry(tarEntry);

    // copy streams
    IOUtils.copy(new ByteArrayInputStream(singleEntryContent), outputStream);
    outputStream.closeArchiveEntry();

    // delete the temp file
    FileUtils.forceDelete(tmpFile);
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:CompressedXmiWriter.java

示例3: addFileToTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
/**
 * Recursively adds a directory to a .tar.gz. Adapted from http://stackoverflow.com/questions/13461393/compress-directory-to-tar-gz-with-commons-compress
 *
 * @param tOut The .tar.gz to add the directory to
 * @param path The location of the folders and files to add
 * @param base The base path of entry in the .tar.gz
 * @throws IOException Any exceptions thrown during tar creation
 */
private void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException {
    File f = new File(path);
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);
    Platform.runLater(() -> fileLabel.setText("Processing " + f.getPath()));

    if (f.isFile()) {
        FileInputStream fin = new FileInputStream(f);
        IOUtils.copy(fin, tOut);
        fin.close();
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
            }
        }
    }
}
 
开发者ID:wpilibsuite,项目名称:java-installer,代码行数:31,代码来源:TarJREController.java

示例4: untar

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的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

示例5: extractTar

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的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

示例6: setUp

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
@Before
public void setUp() throws IOException, URISyntaxException {
  // Gets the test resource files.
  Path fileA = Paths.get(Resources.getResource("fileA").toURI());
  Path fileB = Paths.get(Resources.getResource("fileB").toURI());
  Path directoryA = Paths.get(Resources.getResource("directoryA").toURI());

  expectedFileAString = new String(Files.readAllBytes(fileA), StandardCharsets.UTF_8);
  expectedFileBString = new String(Files.readAllBytes(fileB), StandardCharsets.UTF_8);

  // Prepares a test TarStreamBuilder.
  testTarStreamBuilder.addEntry(
      new TarArchiveEntry(fileA.toFile(), "some/path/to/resourceFileA"));
  testTarStreamBuilder.addEntry(new TarArchiveEntry(fileB.toFile(), "crepecake"));
  testTarStreamBuilder.addEntry(new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:17,代码来源:TarStreamBuilderTest.java

示例7: verifyTarArchive

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的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

示例8: TarDriverEntry

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
protected TarDriverEntry(
        final String name,
        final TarArchiveEntry template) {
    super(name, true);
    //this.init = SIZE | MODTIME;
    super.setMode(template.getMode());
    this.setModTime0(template.getModTime().getTime());
    this.setSize0(template.getSize());
    super.setUserId(template.getLongUserId());
    super.setUserName(template.getUserName());
    super.setGroupId(template.getLongGroupId());
    super.setGroupName(template.getGroupName());
    super.setLinkName(template.getLinkName());
    super.setDevMajor(template.getDevMajor());
    super.setDevMinor(template.getDevMinor());
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:17,代码来源:TarDriverEntry.java

示例9: newEntry

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
@Override
public TarDriverEntry newEntry(
        final BitField<FsAccessOption> options,
        String name,
        final Type type,
        final @CheckForNull Entry template) {
    name = normalize(name, type);
    final TarDriverEntry entry;
    if (template instanceof TarArchiveEntry) {
        entry = newEntry(name, (TarArchiveEntry) template);
    } else {
        entry = newEntry(name);
        if (null != template) {
            entry.setModTime(template.getTime(WRITE));
            entry.setSize(template.getSize(DATA));
            for (final Access access : ALL_POSIX_ACCESS)
                for (final PosixEntity entity : ALL_POSIX_ENTITIES)
                    entry.setPermitted(access, entity, template.isPermitted(access, entity));
        }
    }
    return entry;
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:23,代码来源:TarDriver.java

示例10: applyInfo

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
private static void applyInfo ( final TarArchiveEntry entry, final EntryInformation entryInformation, TimestampProvider timestampProvider )
{
    if ( entryInformation == null )
    {
        return;
    }

    if ( entryInformation.getUser () != null )
    {
        entry.setUserName ( entryInformation.getUser () );
    }
    if ( entryInformation.getGroup () != null )
    {
        entry.setGroupName ( entryInformation.getGroup () );
    }
    entry.setMode ( entryInformation.getMode () );
    entry.setModTime ( timestampProvider.getModTime () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DebianPackageWriter.java

示例11: addControlContent

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
private void addControlContent ( final TarArchiveOutputStream out, final String name, final ContentProvider content, final int mode ) throws IOException
{
    if ( content == null || !content.hasContent () )
    {
        return;
    }

    final TarArchiveEntry entry = new TarArchiveEntry ( name );
    if ( mode >= 0 )
    {
        entry.setMode ( mode );
    }

    entry.setUserName ( "root" );
    entry.setGroupName ( "root" );
    entry.setSize ( content.getSize () );
    entry.setModTime ( this.getTimestampProvider ().getModTime () );
    out.putArchiveEntry ( entry );
    try ( InputStream stream = content.createInputStream () )
    {
        ByteStreams.copy ( stream, out );
    }
    out.closeArchiveEntry ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:DebianPackageWriter.java

示例12: addFileToArchive

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
/**
 * add one file to tar.gz file
 *
 * @param file file to be added to the tar.gz
 */
public boolean addFileToArchive(File file, String dirPrefixForTar) {
  try {
    String filePathInTar = dirPrefixForTar + file.getName();

    TarArchiveEntry entry = new TarArchiveEntry(file, filePathInTar);
    entry.setSize(file.length());
    tarOutputStream.putArchiveEntry(entry);
    IOUtils.copy(new FileInputStream(file), tarOutputStream);
    tarOutputStream.closeArchiveEntry();

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

示例13: addFile

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
/**
 * @deprecated see {@link PLP5ProjectParser#parse(File)}
 */
private static void addFile(TarArchiveInputStream plpInputStream,
		TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
		throws IOException
{
	byte[] content = new byte[(int) entry.getSize()];
	int currentIndex = 0;
	while (currentIndex < entry.getSize())
	{
		plpInputStream.read(content, currentIndex, content.length - currentIndex);
		currentIndex++;
	}
	if (entry.getName().endsWith(".asm"))
	{
		ASMFile asmFile = new SimpleASMFile(null, entry.getName());
		asmFile.setContent(new String(content));
		projectFiles.add(asmFile);
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:22,代码来源:FileUtil.java

示例14: extract

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
private void extract(File projectFile) throws IOException
{
	try (FileInputStream fileStream = new FileInputStream(projectFile);
			TarArchiveInputStream inputStream = new TarArchiveInputStream(fileStream))
	{
		this.inputStream = inputStream;
		
		// TODO: verify the first entry is not relevant
		TarArchiveEntry entry = inputStream.getNextTarEntry();
		while ((entry = inputStream.getNextTarEntry()) != null)
		{
			if (!entry.isDirectory())
			{
				addFile(entry);
			}
			else
			{
				addDirectory(entry);
			}
		}
	}
	catch (IOException exception)
	{
		throw exception;
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:27,代码来源:PLP5ProjectParser.java

示例15: addFile

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入依赖的package包/类
private void addFile(TarArchiveEntry entry) throws IOException
{
	byte[] content = new byte[(int) entry.getSize()];
	int currentIndex = 0;
	while (currentIndex < entry.getSize())
	{
		inputStream.read(content, currentIndex, content.length - currentIndex);
		currentIndex++;
	}
	if (entry.getName().endsWith(".asm"))
	{
		ASMFile asmFile = new SimpleASMFile(project, entry.getName());
		asmFile.setContent(new String(content));
		
		project.add(asmFile);
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:18,代码来源:PLP5ProjectParser.java


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