Package sonia.scm.util
Class Archives
java.lang.Object
sonia.scm.util.Archives
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic classClassed used inextractTar(InputStream, Path).static classClass used inaddPathToTar(Path, OutputStream). -
Method Summary
Modifier and TypeMethodDescriptionstatic Archives.TarWriteraddPathToTar(Path path, OutputStream outputStream) Prepare bundling a completePathin a tar.static org.apache.commons.compress.archivers.tar.TarArchiveInputStreamcreateTarInputStream(InputStream source) Creates a tar input stream that takes its bytes from the given input stream.static org.apache.commons.compress.archivers.tar.TarArchiveOutputStreamCreates a tar output stream that is backed by the given output stream.static Archives.TarExtractorextractTar(InputStream inputStream, Path targetPath) Extracts files from a input stream with a tar.
-
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
Prepare bundling a completePathin 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
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.
-