Пример #1
0
  private static void addEntry(
      final String pName, final String pContent, final TarOutputStream pOutput) throws IOException {
    final byte[] data = pContent.getBytes("UTF-8");

    final TarEntry entry = new TarEntry("./" + pName);
    entry.setSize(data.length);
    entry.setNames("root", "root");

    pOutput.putNextEntry(entry);
    pOutput.write(data);
    pOutput.closeEntry();
  }
Пример #2
0
  public TarEntry map(final TarEntry pEntry) {

    final String name = pEntry.getName();

    final TarEntry newEntry = new TarEntry(prefix + '/' + Utils.stripPath(strip, name));

    newEntry.setUserId(pEntry.getUserId());
    newEntry.setGroupId(pEntry.getGroupId());
    newEntry.setUserName(pEntry.getUserName());
    newEntry.setGroupName(pEntry.getGroupName());
    newEntry.setMode(pEntry.getMode());
    newEntry.setSize(pEntry.getSize());

    return newEntry;
  }
Пример #3
0
  @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
    }
  }
Пример #4
0
/*