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


Java TarInputStream类代码示例

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


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

示例1: getInputStream

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
/**
 * Return an InputStream for reading the contents of this Resource.
 * @return an InputStream object.
 * @throws IOException if the tar file cannot be opened,
 *         or the entry cannot be read.
 */
@Override
public InputStream getInputStream() throws IOException {
    if (isReference()) {
        return getCheckedRef().getInputStream();
    }
    Resource archive = getArchive();
    final TarInputStream i = new TarInputStream(archive.getInputStream());
    TarEntry te;
    while ((te = i.getNextEntry()) != null) {
        if (te.getName().equals(getName())) {
            return i;
        }
    }

    FileUtils.close(i);
    throw new BuildException("no entry " + getName() + " in "
                             + getArchive());
}
 
开发者ID:apache,项目名称:ant,代码行数:25,代码来源:TarResource.java

示例2: extractBzip

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
private void extractBzip(File downloadFile)
    throws IOException
{
  try (FileInputStream inputSkipTwo = new FileInputStream(downloadFile)) {
    // see javadoc for CBZip2InputStream
    // first two bits need to be skipped
    inputSkipTwo.read();
    inputSkipTwo.read();

    LOG.debug("Extract tar...");
    try (TarInputStream tarIn = new TarInputStream(new CBZip2InputStream(inputSkipTwo))) {
      for (TarEntry entry = tarIn.getNextEntry(); entry != null; entry = tarIn.getNextEntry()) {
        LOG.debug("Extracting {}", entry.getName());

        File extractedFile = new File(downloadFile.getParent() + File.separator + entry.getName());
        extractEntry(extractedFile, entry.isDirectory(), tarIn);
      }
    }
  }
}
 
开发者ID:partnet,项目名称:seauto,代码行数:21,代码来源:StandaloneDriverDownloadAssistant.java

示例3: setup

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
/**
 * @throws IOException
 */
@Before
public void setup() throws IOException {
	hadoopCommand = "-i %s -om %s -ro %s";
	final TarInputStream tin = new TarInputStream(new GZIPInputStream(
			CorrelationModeTest.class.getResourceAsStream("/org/openimaj/hadoop/tools/twitter/dfidf.out.tar.gz")));
	TarEntry entry = null;
	output = folder.newFile("results.out");
	output.delete();
	output.mkdir();
	dest = folder.newFile("DFIDF.out");
	dest.delete();
	dest.mkdir();

	while ((entry = tin.getNextEntry()) != null) {
		final File tdst = new File(dest.toString(), entry.getName());
		if (entry.isDirectory()) {
			tdst.mkdir();
		} else {
			final FileOutputStream fout = new FileOutputStream(tdst);
			tin.copyEntryContents(fout);
			fout.close();
		}
	}
	tin.close();
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:29,代码来源:CorrelationModeTest.java

示例4: fetchEntry

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
/**
 * fetches information from the named entry inside the archive.
 */
@Override
protected void fetchEntry() {
    Resource archive = getArchive();
    try (TarInputStream i = new TarInputStream(archive.getInputStream())) {
        TarEntry te = null;
        while ((te = i.getNextEntry()) != null) {
            if (te.getName().equals(getName())) {
                setEntry(te);
                return;
            }
        }
    } catch (IOException e) {
        log(e.getMessage(), Project.MSG_DEBUG);
        throw new BuildException(e);
    }
    setEntry(null);
}
 
开发者ID:apache,项目名称:ant,代码行数:21,代码来源:TarResource.java

示例5: expandStream

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
/**
 * @since Ant 1.7
 */
private void expandStream(String name, InputStream stream, File dir)
    throws IOException {
    try (TarInputStream tis = new TarInputStream(
        compression.decompress(name, new BufferedInputStream(stream)),
        getEncoding())) {
        log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
        boolean empty = true;
        FileNameMapper mapper = getMapper();
        TarEntry te;
        while ((te = tis.getNextEntry()) != null) {
            empty = false;
            extractFile(FileUtils.getFileUtils(), null, dir, tis,
                        te.getName(), te.getModTime(),
                        te.isDirectory(), mapper);
        }
        if (empty && getFailOnEmptyArchive()) {
            throw new BuildException("archive '%s' is empty", name);
        }
        log("expand complete", Project.MSG_VERBOSE);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:25,代码来源:Untar.java

示例6: testAddFileNoStrip

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Test
public void testAddFileNoStrip ()
    throws Exception
{
    final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR);

    TarInputStream input = null;
    try {
        tar.addFile(TEST_FILE);
        tar.close();

        input = getTarInput(tar);
        final TarEntry entry = input.getNextEntry();

        // verify the header looks correct
        assertEquals(PathUtils.stripLeadingSeparators(TEST_FILE.getAbsolutePath()), entry.getName());

        // verify there are no more entries in the tar file.
        assertNull(input.getNextEntry());

    } finally {
        tar.delete();
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:leplastrier,项目名称:jpkg-library,代码行数:26,代码来源:PackageTarFileTest.java

示例7: testTrailingDirectorySlashAdded

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Test
public void testTrailingDirectorySlashAdded ()
    throws Exception
{
    final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR);

    TarInputStream input = null;
    try {
        tar.addFile(TEST_DIR, DESTROOT);
        tar.close();

        input = getTarInput(tar);
        final TarEntry entry = input.getNextEntry();

        // verify the name has a trailing /
        assertEquals("directory/", entry.getName());

        // verify there are no more entries in the tar file.
        assertNull(input.getNextEntry());

    } finally {
        tar.delete();
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:leplastrier,项目名称:jpkg-library,代码行数:26,代码来源:PackageTarFileTest.java

示例8: tryOpenAsArchive

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
static public InputStream tryOpenAsArchive (File file, String mimeType, String contentType) {
  String fileName = file.getName ();
  try {
    if (fileName.endsWith (".tar.gz") || fileName.endsWith (".tgz")) {
      return new TarInputStream (new GZIPInputStream (new FileInputStream (file)));
    } else if (fileName.endsWith (".tar.bz2")) {
      return new TarInputStream (new CBZip2InputStream (new FileInputStream (file)));
    } else if (fileName.endsWith (".tar") || "application/x-tar".equals (contentType)) {
      return new TarInputStream (new FileInputStream (file));
    } else if (fileName.endsWith (".zip")
               || "application/x-zip-compressed".equals (contentType)
               || "application/zip".equals (contentType)
               || "application/x-compressed".equals (contentType)
               || "multipar/x-zip".equals (contentType)) {
      return new ZipInputStream (new FileInputStream (file));
    } else if (fileName.endsWith (".kmz")) {
      return new ZipInputStream (new FileInputStream (file));
    }
  } catch (IOException e) {}
  return null;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:22,代码来源:ImportingUtilities.java

示例9: untar

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
protected void untar (File destDir, InputStream inputStream) throws IOException {
  TarInputStream tin = new TarInputStream (inputStream);
  TarEntry tarEntry = null;

  while ((tarEntry = tin.getNextEntry ()) != null) {
    File destEntry = new File (destDir, tarEntry.getName ());
    File parent = destEntry.getParentFile ();

    if (!parent.exists ()) {
      parent.mkdirs ();
    }

    if (tarEntry.isDirectory ()) {
      destEntry.mkdirs ();
    } else {
      FileOutputStream fout = new FileOutputStream (destEntry);
      try {
        tin.copyEntryContents (fout);
      } finally {
        fout.close ();
      }
    }
  }

  tin.close ();
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:27,代码来源:FileProjectManager.java

示例10: extractTar

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
public boolean extractTar() throws IOException {
	logger.info("Extract prism archive: "+prismArchive);
	InputStream gzStream = prismArchive.openStream();
       TarInputStream tarStream = new TarInputStream(new GZIPInputStream(gzStream));
       TarEntry tarEntry;
       while((tarEntry=tarStream.getNextEntry()) != null) {
		File destPath = new File(prismDestinationDir,tarEntry.getName());
		if (tarEntry.isDirectory()) {
			destPath.mkdir();
			continue;
		}
		FileOutputStream fout = new FileOutputStream(destPath);
		tarStream.copyEntryContents(fout);
		fout.close();
		if(tarEntry.getName().endsWith("install.sh"))
			destPath.setExecutable(true);
	}
	tarStream.close();
	gzStream.close();
	return true;		
}
 
开发者ID:aciancone,项目名称:klapersuite,代码行数:22,代码来源:PrismRunner.java

示例11: unpack

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Override
public void unpack(final TaskOutputsInternal taskOutputs, InputStream input, final TaskOutputOriginReader readOrigin) {
    IoActions.withResource(new TarInputStream(input), new Action<TarInputStream>() {
        @Override
        public void execute(TarInputStream tarInput) {
            try {
                unpack(taskOutputs, tarInput, readOrigin);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:TarTaskOutputPacker.java

示例12: unzip

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
public static File unzip(File folder, ByteBuffer buf) throws IOException {
    File outputFolder = new File(folder, Long.toString(System.currentTimeMillis()));
    log.debug("Unzipping into " + outputFolder.getAbsoluteFile().getAbsolutePath());

    if (outputFolder.exists()) {
        throw new IOException(String.format("Folder already exists at %s, please attempt submission again", outputFolder.getAbsoluteFile().getAbsolutePath()));
    } else {
        boolean folderCreated = outputFolder.mkdir();
        if (!folderCreated) {
            throw new IOException(String.format("Folder for submission could not be created at %s", outputFolder.getAbsoluteFile().getAbsolutePath()));
        }
    }

    TarInputStream tar = new TarInputStream(new GZIPInputStream(new ByteArrayInputStream(buf.array())));
    TarEntry entry = tar.getNextEntry();

    while (entry != null) {
        String fileName = entry.getName();
        File newFile = new File(outputFolder, fileName);

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        new File(newFile.getParent()).mkdirs();

        if (!entry.isDirectory()) {
            FileOutputStream fos = new FileOutputStream(newFile);
            tar.copyEntryContents(fos);
            fos.close();
        }
        entry = tar.getNextEntry();
    }

    tar.close();
    return outputFolder;
}
 
开发者ID:ezbake,项目名称:ezbake-azkaban-submitter,代码行数:36,代码来源:UnzipUtil.java

示例13: testAddFile

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Test
public void testAddFile ()
    throws Exception
{
    final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR);

    TarInputStream input = null;
    try {
        tar.addFile(TEST_FILE, DESTROOT);
        tar.close();

        input = getTarInput(tar);
        final TarEntry entry = input.getNextEntry();

        // verify the header looks correct
        assertEquals("file.txt", entry.getName());
        assertEquals(TEST_FILE.length(), entry.getSize());
        assertEquals(UnixStandardPermissions.ROOT_USER.getName(), entry.getUserName());
        assertEquals(UnixStandardPermissions.ROOT_USER.getId(), entry.getUserId());
        assertEquals(UnixStandardPermissions.ROOT_GROUP.getName(), entry.getGroupName());
        assertEquals(UnixStandardPermissions.ROOT_GROUP.getId(), entry.getGroupId());
        assertEquals(Integer.toOctalString(UnixStandardPermissions.STANDARD_FILE_MODE),
                     Integer.toOctalString(entry.getMode()));
        assertEquals(TEST_FILE.lastModified(), entry.getModTime().getTime());

        // verify the file data looks correct.
        final byte[] data = new byte[(int)entry.getSize()];
        input.read(data);
        final byte[] fileData = FileUtils.readFileToByteArray(TEST_FILE);
        assertTrue(Arrays.equals(fileData, data));

        // verify there are no more entries in the tar file.
        assertNull(input.getNextEntry());

    } finally {
        tar.delete();
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:leplastrier,项目名称:jpkg-library,代码行数:40,代码来源:PackageTarFileTest.java

示例14: testPermissionMatchesExactPath

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Test
public void testPermissionMatchesExactPath ()
    throws Exception
{
    final PermissionsMap permissions = new PermissionsMap();
    permissions.addPathPermissions("/directory/file.txt", new PathPermissions(TEST_USER, TEST_GROUP, TEST_MODE, false));

    final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR, permissions);

    TarInputStream input = null;
    try {
        tar.addFile(TEST_DIR_FILE, DESTROOT);
        tar.close();

        input = getTarInput(tar);

        final TarEntry entry = input.getNextEntry();
        assertEquals("directory/file.txt", entry.getName());
        assertEquals(TEST_USER, entry.getUserName());
        assertEquals(TEST_GROUP, entry.getGroupName());
        assertEquals(TEST_MODE, entry.getMode());

        assertNull(input.getNextEntry());
    } finally {
        tar.delete();
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:leplastrier,项目名称:jpkg-library,代码行数:29,代码来源:PackageTarFileTest.java

示例15: testRecursivePermissionMatchesExactPath

import org.apache.tools.tar.TarInputStream; //导入依赖的package包/类
@Test
public void testRecursivePermissionMatchesExactPath ()
    throws Exception
{
    final PermissionsMap permissions = new PermissionsMap();
    permissions.addPathPermissions("/directory/file.txt", new PathPermissions(TEST_USER, TEST_GROUP, TEST_MODE, true));

    final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR, permissions);

    TarInputStream input = null;
    try {
        tar.addFile(TEST_DIR_FILE, DESTROOT);
        tar.close();

        input = getTarInput(tar);

        final TarEntry entry = input.getNextEntry();
        assertEquals("directory/file.txt", entry.getName());
        assertEquals(TEST_USER, entry.getUserName());
        assertEquals(TEST_GROUP, entry.getGroupName());
        assertEquals(TEST_MODE, entry.getMode());

        assertNull(input.getNextEntry());
    } finally {
        tar.delete();
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:leplastrier,项目名称:jpkg-library,代码行数:29,代码来源:PackageTarFileTest.java


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