Class Archives

java.lang.Object
sonia.scm.util.Archives

public final class Archives extends Object
  • Method Details

    • createTarOutputStream

      public static org.apache.commons.compress.archivers.tar.TarArchiveOutputStream createTarOutputStream(OutputStream dest)
      Creates a tar output stream that is backed by the given output stream.
      Parameters:
      dest - The stream the tar should be written to.
    • createTarInputStream

      public static org.apache.commons.compress.archivers.tar.TarArchiveInputStream createTarInputStream(InputStream source)
      Creates a tar input stream that takes its bytes from the given input stream.
      Parameters:
      source - The stream the tar should be extracted from.
    • addPathToTar

      public static Archives.TarWriter addPathToTar(Path path, OutputStream outputStream)
      Prepare bundling a complete Path in a tar. Aside from the path whose files shall be added to the tar, it is possible to specify a base path for the tar archive (Archives.TarWriter.withBasePath(String)) and to specify a filter to select what files shall be added (Archives.TarWriter.withFilter(Predicate)). To start the process, Archives.TarWriter.run() has to be called.
      Example:
         Archives.addPathToTar(Paths.get("some/dir"), Files.newOutputStream("my.tar"))
           .filter(path -> !path.toString().endsWith("~"))
           .run();
       
      Parameters:
      path - The path containing the files to be added to the tar.
      outputStream - The output stream the tar shall be written to.
      Returns:
      Instance of Archives.TarWriter.
    • extractTar

      public static Archives.TarExtractor extractTar(InputStream inputStream, Path targetPath)
      Extracts files from a input stream with a tar.
      Example:
         Archives.extractTar(Files.newOutputStream("my.tar"), Paths.get("target/dir"))
           .run();
       
      Parameters:
      inputStream - The input stream providing the tar stream.
      targetPath - The target path to write the files to.
      Returns:
      Instance of Archives.TarExtractor.