static void unTarUsingJava(File inFile, File untarDir,
      boolean gzipped) throws IOException {
    InputStream inputStream = null;
    TarArchiveInputStream tis = null;
    try {
      if (gzipped) {
        inputStream =
            new GZIPInputStream(Files.newInputStream(inFile.toPath()));
      } else {
        inputStream = Files.newInputStream(inFile.toPath());
      }

      inputStream = new BufferedInputStream(inputStream);

      tis = new TarArchiveInputStream(inputStream);

      for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null;) {
        unpackEntries(tis, entry, untarDir);
        entry = tis.getNextTarEntry();
      }
    } finally {
      IOUtils.cleanupWithLogger(LOG, tis, inputStream);
    }
  }
@Test(expected = IOException.class)
  public void testCreateArbitrarySymlinkUsingJava() throws IOException {
    final File simpleTar = new File(del, FILE);
    OutputStream os = new FileOutputStream(simpleTar);

    File rootDir = new File("tmp");
    try (TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) {
      tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

      // Create arbitrary dir
      File arbitraryDir = new File(rootDir, "arbitrary-dir/");
      Verify.mkdirs(arbitraryDir);

      // We will tar from the tar-root lineage
      File tarRoot = new File(rootDir, "tar-root/");
      File symlinkRoot = new File(tarRoot, "dir1/");
      Verify.mkdirs(symlinkRoot);

      // Create Symbolic Link to an arbitrary dir
      java.nio.file.Path symLink = Paths.get(symlinkRoot.getPath(), "sl");
      Files.createSymbolicLink(symLink, arbitraryDir.toPath().toAbsolutePath());

      // Put entries in tar file
      putEntriesInTar(tos, tarRoot);
      putEntriesInTar(tos, new File(symLink.toFile(), "dir-outside-tar-root/"));
      tos.close();

      // Untar using Java
      File untarFile = new File(rootDir, "extracted");
      FileUtil.unTarUsingJava(simpleTar, untarFile, false);
    } finally {
      FileUtils.deleteDirectory(rootDir);
    }
  }