use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project Manga by herrlock.
the class ViewArchive method writeCBT.
private void writeCBT() throws IOException {
logger.traceEntry();
Path folderPath = this.folder.toPath();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folderPath, new ViewPageConstants.PathIsDirectoryFilter())) {
for (Path path : directoryStream) {
logger.debug("Archiving {}", path);
String chapterName = decimalTransform(String.valueOf(path.getFileName()), 4);
Path tarArchive = this.targetFolder.resolve(mangaName() + '-' + chapterName + ".cbt");
logger.debug("Write to: {}", tarArchive);
try (TarArchiveOutputStream archiveZip = new TarArchiveOutputStream(Files.newOutputStream(tarArchive))) {
writeTarEntry(archiveZip, path);
}
if (this.clean) {
logger.debug("Cleaning {}", path);
Files.walkFileTree(path, DELETE_VISITOR);
}
}
}
if (this.clean) {
logger.debug("Cleaning {}", folderPath);
Files.walkFileTree(folderPath, DELETE_VISITOR);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project teku by ConsenSys.
the class ValidatorKeystores method copyDirectoryToTarFile.
private static void copyDirectoryToTarFile(Path inputDirectoryPath, Path outputPath) throws IOException {
File outputFile = outputPath.toFile();
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(bufferedOutputStream)) {
tarArchiveOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
List<File> files = new ArrayList<>(FileUtils.listFiles(inputDirectoryPath.toFile(), new String[] { "json", "txt" }, true));
for (File currentFile : files) {
String relativeFilePath = new File(inputDirectoryPath.toUri()).toURI().relativize(new File(currentFile.getAbsolutePath()).toURI()).getPath();
TarArchiveEntry tarEntry = new TarArchiveEntry(currentFile, relativeFilePath);
tarEntry.setSize(currentFile.length());
tarArchiveOutputStream.putArchiveEntry(tarEntry);
tarArchiveOutputStream.write(Files.readAllBytes(currentFile.toPath()));
tarArchiveOutputStream.closeArchiveEntry();
}
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flink-mirror by flink-ci.
the class YarnTestArchiveJob method archiveFilesInDirectory.
private static void archiveFilesInDirectory(File directory, String target) throws IOException {
for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
Files.write(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()), entry.getValue().getBytes());
}
try (FileOutputStream fos = new FileOutputStream(target);
GzipCompressorOutputStream gos = new GzipCompressorOutputStream(new BufferedOutputStream(fos));
TarArchiveOutputStream taros = new TarArchiveOutputStream(gos)) {
taros.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (File f : directory.listFiles()) {
taros.putArchiveEntry(new TarArchiveEntry(f, directory.getName() + File.separator + f.getName()));
try (FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis)) {
IOUtils.copy(bis, taros);
taros.closeArchiveEntry();
}
}
}
for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
Files.delete(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()));
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project prompto-java by prompto.
the class TarUtils method tar.
public static Path tar(Path srcPath, Path dstPath) throws IOException {
try (OutputStream output = new FileOutputStream(dstPath.toFile())) {
try (TarArchiveOutputStream taos = new TarArchiveOutputStream(output)) {
for (File file : srcPath.toFile().listFiles()) {
ArchiveEntry entry = taos.createArchiveEntry(file, file.getName());
taos.putArchiveEntry(entry);
StreamUtils.copyBytes(file.toURI().toURL(), taos);
taos.closeArchiveEntry();
}
}
}
return dstPath;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project devops-service by open-hand.
the class FileUtil method archive.
/**
* 归档
*
* @param entry
* @return
* @throws IOException
*/
public static String archive(String entry, String outputFilePath) throws IOException {
File file = new File(entry);
TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(outputFilePath + ".tar"));
String base = file.getName();
if (file.isDirectory()) {
archiveDir(file, tos, base);
} else {
archiveHandle(tos, file, base);
}
tos.close();
return outputFilePath + ".tar";
}
Aggregations