本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveOutputStream类的具体用法?Java TarArchiveOutputStream怎么用?Java TarArchiveOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TarArchiveOutputStream类属于org.apache.commons.compress.archivers.tar包,在下文中一共展示了TarArchiveOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFileToTarGz
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
* Recursively adds a directory to a .tar.gz. Adapted from http://stackoverflow.com/questions/13461393/compress-directory-to-tar-gz-with-commons-compress
*
* @param tOut The .tar.gz to add the directory to
* @param path The location of the folders and files to add
* @param base The base path of entry in the .tar.gz
* @throws IOException Any exceptions thrown during tar creation
*/
private void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException {
File f = new File(path);
String entryName = base + f.getName();
TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
tOut.putArchiveEntry(tarEntry);
Platform.runLater(() -> fileLabel.setText("Processing " + f.getPath()));
if (f.isFile()) {
FileInputStream fin = new FileInputStream(f);
IOUtils.copy(fin, tOut);
fin.close();
tOut.closeArchiveEntry();
} else {
tOut.closeArchiveEntry();
File[] children = f.listFiles();
if (children != null) {
for (File child : children) {
addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
}
}
}
}
示例2: tarFolder
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
* Tar a given folder to a file.
*
* @param folder the original folder to tar
* @param destinationFile the destination file
* @param waitingHandler a waiting handler used to cancel the process (can
* be null)
* @throws FileNotFoundException exception thrown whenever a file is not
* found
* @throws ArchiveException exception thrown whenever an error occurred
* while taring
* @throws IOException exception thrown whenever an error occurred while
* reading/writing files
*/
public static void tarFolder(File folder, File destinationFile, WaitingHandler waitingHandler) throws FileNotFoundException, ArchiveException, IOException {
FileOutputStream fos = new FileOutputStream(destinationFile);
try {
BufferedOutputStream bos = new BufferedOutputStream(fos);
try {
TarArchiveOutputStream tarOutput = (TarArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, bos);
try {
tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
File matchFolder = folder;
addFolderContent(tarOutput, matchFolder, waitingHandler);
} finally {
tarOutput.close();
}
} finally {
bos.close();
}
} finally {
fos.close();
}
}
示例3: TarOutputService
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@CreatesObligation
public TarOutputService(
final FsModel model,
final Sink sink,
final TarDriver driver)
throws IOException {
Objects.requireNonNull(model);
this.driver = Objects.requireNonNull(driver);
final OutputStream out = sink.stream();
try {
final TarArchiveOutputStream
taos = this.taos = new TarArchiveOutputStream(out,
DEFAULT_BLKSIZE, DEFAULT_RCDSIZE, driver.getEncoding());
taos.setAddPaxHeadersForNonAsciiNames(driver.getAddPaxHeaderForNonAsciiNames());
taos.setLongFileMode(driver.getLongFileMode());
taos.setBigNumberMode(driver.getBigNumberMode());
} catch (final Throwable ex) {
try {
out.close();
} catch (final Throwable ex2) {
ex.addSuppressed(ex2);
}
throw ex;
}
}
示例4: DebianPackageWriter
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public DebianPackageWriter ( final OutputStream stream, final GenericControlFile packageControlFile, final TimestampProvider timestampProvider ) throws IOException
{
this.packageControlFile = packageControlFile;
this.timestampProvider = timestampProvider;
if ( getTimestampProvider () == null )
{
throw new IllegalArgumentException ( "'timestampProvider' must not be null" );
}
BinaryPackageControlFile.validate ( packageControlFile );
this.ar = new ArArchiveOutputStream ( stream );
this.ar.putArchiveEntry ( new ArArchiveEntry ( "debian-binary", this.binaryHeader.length, 0, 0, AR_ARCHIVE_DEFAULT_MODE, getTimestampProvider ().getModTime () / 1000 ) );
this.ar.write ( this.binaryHeader );
this.ar.closeArchiveEntry ();
this.dataTemp = File.createTempFile ( "data", null );
this.dataStream = new TarArchiveOutputStream ( new GZIPOutputStream ( new FileOutputStream ( this.dataTemp ) ) );
this.dataStream.setLongFileMode ( TarArchiveOutputStream.LONGFILE_GNU );
}
示例5: buildAndAddControlFile
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void buildAndAddControlFile () throws IOException, FileNotFoundException
{
final File controlFile = File.createTempFile ( "control", null );
try
{
try ( GZIPOutputStream gout = new GZIPOutputStream ( new FileOutputStream ( controlFile ) );
TarArchiveOutputStream tout = new TarArchiveOutputStream ( gout ) )
{
tout.setLongFileMode ( TarArchiveOutputStream.LONGFILE_GNU );
addControlContent ( tout, "control", createControlContent (), -1 );
addControlContent ( tout, "md5sums", createChecksumContent (), -1 );
addControlContent ( tout, "conffiles", createConfFilesContent (), -1 );
addControlContent ( tout, "preinst", this.preinstScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
addControlContent ( tout, "prerm", this.prermScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
addControlContent ( tout, "postinst", this.postinstScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
addControlContent ( tout, "postrm", this.postrmScript, EntryInformation.DEFAULT_FILE_EXEC.getMode () );
}
addArFile ( controlFile, "control.tar.gz" );
}
finally
{
controlFile.delete ();
}
}
示例6: addControlContent
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void addControlContent ( final TarArchiveOutputStream out, final String name, final ContentProvider content, final int mode ) throws IOException
{
if ( content == null || !content.hasContent () )
{
return;
}
final TarArchiveEntry entry = new TarArchiveEntry ( name );
if ( mode >= 0 )
{
entry.setMode ( mode );
}
entry.setUserName ( "root" );
entry.setGroupName ( "root" );
entry.setSize ( content.getSize () );
entry.setModTime ( this.getTimestampProvider ().getModTime () );
out.putArchiveEntry ( entry );
try ( InputStream stream = content.createInputStream () )
{
ByteStreams.copy ( stream, out );
}
out.closeArchiveEntry ();
}
示例7: generateAddProjectTarEntries
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@SuppressWarnings("PMD.DoNotUseThreads")
private Runnable generateAddProjectTarEntries(Integration integration, OutputStream os) {
return () -> {
try (
TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generate(integration, applicationJavaMustache));
addTarEntry(tos, "src/main/resources/application.properties", generate(integration, applicationPropertiesMustache));
addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlow(tos, integration));
addTarEntry(tos, "pom.xml", generatePom(integration));
addResource(tos, ".s2i/bin/assemble", "s2i/assemble");
addExtensions(tos, integration);
addAdditionalResources(tos);
LOG.info("Integration [{}]: Project files written to output stream",Names.sanitize(integration.getName()));
} catch (IOException e) {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s",
integration.getName(), e.toString()), e);
}
}
};
}
示例8: addExtensions
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private void addExtensions(TarArchiveOutputStream tos, Integration integration) throws IOException {
final Set<String> extensions = collectDependencies(integration).stream()
.filter(Dependency::isExtension)
.map(Dependency::getId)
.collect(Collectors.toCollection(TreeSet::new));
if (!extensions.isEmpty()) {
addTarEntry(tos, "src/main/resources/loader.properties", generateExtensionLoader(extensions));
for (String extensionId : extensions) {
addTarEntry(
tos,
"extensions/" + Names.sanitize(extensionId) + ".jar",
IOUtils.toByteArray(
extensionDataManager.getExtensionBinaryFile(extensionId)
)
);
}
}
}
示例9: createTarGzipPacker
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
* create TarGzipPacker object
*/
public static TarGzipPacker createTarGzipPacker(String targetDir, Config config) {
// this should be received from config
String archiveFilename = SchedulerContext.jobPackageFileName(config);
Path archiveFile = Paths.get(targetDir + "/" + archiveFilename);
try {
// construct output stream
OutputStream outStream = Files.newOutputStream(archiveFile);
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(outStream);
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);
return new TarGzipPacker(archiveFile, tarOutputStream);
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive file can not be created: " + archiveFile, ioe);
return null;
}
}
示例10: createTarGZ
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public static void createTarGZ(String dirPath, String tarGzPath, boolean deleteTempDir) throws IOException {
try (
OutputStream fOut = new FileOutputStream(new File(tarGzPath));
OutputStream bOut = new BufferedOutputStream(fOut);
OutputStream gzOut = new GzipCompressorOutputStream(bOut);
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)
)
{
File f = new File(dirPath);
if (f.isDirectory()) {
//pass over all the files in the directory
File[] children = f.listFiles();
if (children != null) {
for (File child : children) {
addFileToTarGz(tOut, child);
}
}
if(deleteTempDir) {
deleteTempFolder(dirPath);
}
} else {
System.out.println("The given directury path is not a directory");
}
}
}
示例11: addFileToTarGz
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
* This function copies a given file to the zip file
*
* @param tarArchiveOutputStream tar output stream of the zip file
* @param file the file to insert to the zar file
*
* @throws IOException
*/
private static void addFileToTarGz(TarArchiveOutputStream tarArchiveOutputStream, File file)
throws IOException
{
String entryName = file.getName();
TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
tarArchiveOutputStream.putArchiveEntry(tarEntry);
if (file.isFile()) {
try (FileInputStream input = new FileInputStream(file))
{
IOUtils.copy(input, tarArchiveOutputStream);
}
tarArchiveOutputStream.closeArchiveEntry();
} else {//Directory
System.out.println("The directory which need to be packed to tar folder cannot contain other directories");
}
}
示例12: initialize
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
@Override
public void initialize(UimaContext aContext)
throws ResourceInitializationException
{
super.initialize(aContext);
// some param check
if (!outputFile.getName().endsWith(".tar.gz")) {
throw new ResourceInitializationException(
new IllegalArgumentException("Output file must have .tar.gz extension"));
}
typeSystemWritten = false;
try {
outputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(
new BufferedOutputStream(new FileOutputStream(outputFile))));
}
catch (IOException ex) {
throw new ResourceInitializationException(ex);
}
}
示例13: archiveDir
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
/**
* 目录归档
*
* @param dir
* @param taos
* TarArchiveOutputStream
* @param basePath
* @throws Exception
*/
private static void archiveDir(File dir, TarArchiveOutputStream taos,
String basePath) throws Exception {
File[] files = dir.listFiles();
if (files.length < 1) {
TarArchiveEntry entry = new TarArchiveEntry(basePath
+ dir.getName() + PATH);
taos.putArchiveEntry(entry);
taos.closeArchiveEntry();
}
for (File file : files) {
// 递归归档
archive(file, taos, basePath + dir.getName() + PATH);
}
}
示例14: tar
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
public static void tar(Path inputPath, Path outputPath) throws IOException {
if (!Files.exists(inputPath)) {
throw new FileNotFoundException("File not found " + inputPath);
}
try (TarArchiveOutputStream tarArchiveOutputStream = buildTarStream(outputPath.toFile())) {
if (!Files.isDirectory(inputPath)) {
TarArchiveEntry tarEntry = new TarArchiveEntry(inputPath.toFile().getName());
if (inputPath.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
putTarEntry(tarArchiveOutputStream, tarEntry, inputPath);
} else {
Files.walkFileTree(inputPath,
new TarDirWalker(inputPath, tarArchiveOutputStream));
}
tarArchiveOutputStream.flush();
}
}
示例15: generateAddProjectTarEntries
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入依赖的package包/类
private Runnable generateAddProjectTarEntries(GenerateProjectRequest request, OutputStream os) {
return () -> {
try (
TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generateFromRequest(request, applicationJavaMustache));
addTarEntry(tos, "src/main/resources/application.properties", generateFromRequest(request, applicationPropertiesMustache));
addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlowYaml(tos, request));
addTarEntry(tos, "pom.xml", generatePom(request.getIntegration()));
addAdditionalResources(tos);
LOG.info("Integration [{}]: Project files written to output stream",Names.sanitize(request.getIntegration().getName()));
} catch (IOException e) {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s",
request.getIntegration().getName(), e.toString()), e);
}
}
};
}