Java Code Examples for org.apache.tools.tar.TarEntry#setSize()

The following examples show how to use org.apache.tools.tar.TarEntry#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TarCopyAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void visitFile(FileCopyDetails fileDetails) {
    try {
        TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
        archiveEntry.setModTime(fileDetails.getLastModified());
        archiveEntry.setSize(fileDetails.getSize());
        archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());
        tarOutStr.putNextEntry(archiveEntry);
        fileDetails.copyTo(tarOutStr);
        tarOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);
    }
}
 
Example 2
Source File: TarCopyAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void visitFile(FileCopyDetails fileDetails) {
    try {
        TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
        archiveEntry.setModTime(fileDetails.getLastModified());
        archiveEntry.setSize(fileDetails.getSize());
        archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());
        tarOutStr.putNextEntry(archiveEntry);
        fileDetails.copyTo(tarOutStr);
        tarOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);
    }
}
 
Example 3
Source File: TestFileUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 30000)
public void testUnTar() throws IOException {
  setupDirs();
  
  // make a simple tar:
  final File simpleTar = new File(del, FILE);
  OutputStream os = new FileOutputStream(simpleTar); 
  TarOutputStream tos = new TarOutputStream(os);
  try {
    TarEntry te = new TarEntry("/bar/foo");
    byte[] data = "some-content".getBytes("UTF-8");
    te.setSize(data.length);
    tos.putNextEntry(te);
    tos.write(data);
    tos.closeEntry();
    tos.flush();
    tos.finish();
  } finally {
    tos.close();
  }

  // successfully untar it into an existing dir:
  FileUtil.unTar(simpleTar, tmp);
  // check result:
  assertTrue(new File(tmp, "/bar/foo").exists());
  assertEquals(12, new File(tmp, "/bar/foo").length());
  
  final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
  regularFile.createNewFile();
  assertTrue(regularFile.exists());
  try {
    FileUtil.unTar(simpleTar, regularFile);
    assertTrue("An IOException expected.", false);
  } catch (IOException ioe) {
    // okay
  }
}
 
Example 4
Source File: TestFileUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 30000)
public void testUnTar() throws IOException {
  setupDirs();
  
  // make a simple tar:
  final File simpleTar = new File(del, FILE);
  OutputStream os = new FileOutputStream(simpleTar); 
  TarOutputStream tos = new TarOutputStream(os);
  try {
    TarEntry te = new TarEntry("/bar/foo");
    byte[] data = "some-content".getBytes("UTF-8");
    te.setSize(data.length);
    tos.putNextEntry(te);
    tos.write(data);
    tos.closeEntry();
    tos.flush();
    tos.finish();
  } finally {
    tos.close();
  }

  // successfully untar it into an existing dir:
  FileUtil.unTar(simpleTar, tmp);
  // check result:
  assertTrue(new File(tmp, "/bar/foo").exists());
  assertEquals(12, new File(tmp, "/bar/foo").length());
  
  final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
  regularFile.createNewFile();
  assertTrue(regularFile.exists());
  try {
    FileUtil.unTar(simpleTar, regularFile);
    assertTrue("An IOException expected.", false);
  } catch (IOException ioe) {
    // okay
  }
}
 
Example 5
Source File: TarCopyAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void visitFile(FileCopyDetails fileDetails) {
    try {
        TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
        archiveEntry.setModTime(fileDetails.getLastModified());
        archiveEntry.setSize(fileDetails.getSize());
        archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());
        tarOutStr.putNextEntry(archiveEntry);
        fileDetails.copyTo(tarOutStr);
        tarOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);
    }
}
 
Example 6
Source File: TarCopyAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void visitFile(FileCopyDetails fileDetails) {
    try {
        TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
        archiveEntry.setModTime(fileDetails.getLastModified());
        archiveEntry.setSize(fileDetails.getSize());
        archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());
        tarOutStr.putNextEntry(archiveEntry);
        fileDetails.copyTo(tarOutStr);
        tarOutStr.closeEntry();
    } catch (Exception e) {
        throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);
    }
}