本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveOutputStream.close方法的具体用法?Java TarArchiveOutputStream.close怎么用?Java TarArchiveOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
的用法示例。
在下文中一共展示了TarArchiveOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: createArchive
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
* Create a gzipped tar archive containing the ProGuard/Native mapping files
*
* @param files array of mapping.txt files
* @return the tar-gzipped archive
*/
private static File createArchive(List<File> files, String uuid) {
try {
File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz");
TarArchiveOutputStream taos = new TarArchiveOutputStream(
new GZIPOutputStream(
new BufferedOutputStream(
new FileOutputStream(tarZippedFile))));
for (File file : files) {
taos.putArchiveEntry(new TarArchiveEntry(file,
(uuid != null && !uuid.isEmpty() ? uuid : UUID.randomUUID()) + ".txt"));
IOUtils.copy(new FileInputStream(file), taos);
taos.closeArchiveEntry();
}
taos.finish();
taos.close();
return tarZippedFile;
} catch (IOException e) {
failWithError("IO Exception while trying to tar and zip the file.", e);
return null;
}
}
示例3: compressData
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
* Compress data
*
* @param fileCompressor
* FileCompressor object
* @return
* @throws Exception
*/
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream aos = new TarArchiveOutputStream(baos);
try {
for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
.values()) {
TarArchiveEntry entry = new TarArchiveEntry(
binaryFile.getDesPath());
entry.setSize(binaryFile.getActualSize());
aos.putArchiveEntry(entry);
aos.write(binaryFile.getData());
aos.closeArchiveEntry();
}
aos.flush();
aos.finish();
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on compress data", e);
} finally {
aos.close();
baos.close();
}
return baos.toByteArray();
}
示例4: archiveDB
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public static void archiveDB(final String location, final String target) {
try {
System.out.println("Dumping " + location + " to " + target);
final File root = new File(location);
final File targetFile = new File(target);
TarArchiveOutputStream tarGz = new TarArchiveOutputStream(new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream(targetFile)), 0x1000));
for (final File file : IOUtil.listFiles(root)) {
final long fileSize = file.length();
if (file.isFile() && fileSize != 0) {
CompressBackupUtil.archiveFile(tarGz, new BackupStrategy.FileDescriptor(file, ""), fileSize);
}
}
tarGz.close();
} catch (IOException ioe) {
System.out.println("Can't create backup");
}
}
示例5: apply
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private File apply(String archiveFilename, File outputDir) throws ArchiveException, IOException {
File archive = new File(outputDir, (archiveFilename + ".tar"));
FileOutputStream tarOutput = new FileOutputStream(archive);
TarArchiveOutputStream tarBall = (TarArchiveOutputStream)new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, tarOutput);
tarBall.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
try {
addFilesToTar(tarBall, new File(workingDir, directory));
} finally {
tarBall.close();
}
File outputFile = new File(outputDir, (archiveFilename));
compress(archive, outputFile);
FileUtils.deleteQuietly(archive);
return outputFile;
}
示例6: create
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
@Override
public void create() {
createBackupDir();
String name = append + "_" + getDateTime() + "." + fileEnding;
String tarFile = backup.getAbsolutePath() + File.separator + name;
try {
logger.info("Creating zip file " + tarFile);
FileOutputStream fos = new FileOutputStream(tarFile);
TarArchiveOutputStream tos = new TarArchiveOutputStream(fos);
addDirToArchive(tos, repository);
tos.close();
} catch(IOException ioe) {
logger.error("Error creating zip file: " + ioe.getMessage());
}
}
示例7: compress
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public void compress(final File rootDir) throws IOException {
boolean deleteIncompleteTarGzFile = false;
final OutputStream fout = castStream(tarGzFile.createOutputStream());
try {
deleteIncompleteTarGzFile = true;
final GzipParameters gzipParameters = new GzipParameters();
gzipParameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
final TarArchiveOutputStream out = new TarArchiveOutputStream(new GzipCompressorOutputStream(new BufferedOutputStream(fout), gzipParameters));
try {
writeTar(out, rootDir, rootDir);
} finally {
out.close();
}
deleteIncompleteTarGzFile = false;
} finally {
fout.close();
if (deleteIncompleteTarGzFile)
tarGzFile.delete();
}
}
示例8: compressFiles
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public static void compressFiles(Collection<File> files, File output)
throws IOException {
// Create the output stream for the output file
FileOutputStream fos = new FileOutputStream(output);
// Wrap the output file stream in streams that will tar and gzip everything
TarArchiveOutputStream taos = new TarArchiveOutputStream(
new GZIPOutputStream(new BufferedOutputStream(fos)));
// TAR has an 8 gig file limit by default, this gets around that
taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); // to get past the 8 gig limit
// TAR originally didn't support long file names, so enable the support for it
taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
// Get to putting all the files in the compressed output file
for (File f : files) {
addFilesToCompression(taos, f, ".");
}
// Close everything up
taos.close();
fos.close();
}
示例9: copyFileOut
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public void copyFileOut(String containerId, File output, String pathInContainer)
throws DockerException, InterruptedException, IOException {
File temp = new File(output.getParent() + File.separator + "_temp.tar");
Files.createParentDirs(temp);
if (!temp.createNewFile())
throw new IOException("can not new temp file: " + temp.toString());
TarArchiveOutputStream aos = new TarArchiveOutputStream(new FileOutputStream(temp));
try (final TarArchiveInputStream tarStream = new TarArchiveInputStream(
client.archiveContainer(containerId, pathInContainer))) {
TarArchiveEntry entry;
while ((entry = tarStream.getNextTarEntry()) != null) {
aos.putArchiveEntry(entry);
IOUtils.copy(tarStream, aos);
aos.closeArchiveEntry();
}
}
aos.finish();
aos.close();
boolean unTarStatus = unTar(new TarArchiveInputStream(new FileInputStream(temp)), output.getParent());
StringBuilder builder = new StringBuilder();
if (!unTarStatus)
throw new RuntimeException("un tar file error");
if (!temp.delete())
builder.append("temp file delete failed, but ");
LOGGER.info(builder.append("copy files ").append(pathInContainer).append(" out of container ")
.append(containerId).append(" successful").toString());
}
示例10: tar
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public static void tar(File[] files, String destinationPath) throws IOException {
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(new FileOutputStream(destinationPath));
for(File file : files) {
TarArchiveEntry entry = new TarArchiveEntry(file, file.getName());
tarOutput.putArchiveEntry(entry);
FileInputStream in = new FileInputStream(file);
IOUtils.copy(in, tarOutput);
in.close();
tarOutput.closeArchiveEntry();
}
tarOutput.close();
}
示例11: createTarFile
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
static LocalResource createTarFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".tar");
archiveFile.createNewFile();
TarArchiveOutputStream out = new TarArchiveOutputStream(
new FileOutputStream(archiveFile));
TarArchiveEntry entry = new TarArchiveEntry(p.getName());
entry.setSize(bytes.length);
out.putArchiveEntry(entry);
out.write(bytes);
out.closeArchiveEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".tar")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar"))
.getModificationTime());
return ret;
}
示例12: createTgzFile
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
static LocalResource createTgzFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File gzipFile = new File(p.toUri().getPath() + ".tar.gz");
gzipFile.createNewFile();
TarArchiveOutputStream out = new TarArchiveOutputStream(
new GZIPOutputStream(new FileOutputStream(gzipFile)));
TarArchiveEntry entry = new TarArchiveEntry(p.getName());
entry.setSize(bytes.length);
out.putArchiveEntry(entry);
out.write(bytes);
out.closeArchiveEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".tar.gz")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar.gz"))
.getModificationTime());
return ret;
}
示例13: archive
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
* 归档
*
* @param srcFile
* 源路径
* @param destPath
* 目标路径
* @throws Exception
*/
public static void archive(File srcFile, File destFile) throws Exception {
TarArchiveOutputStream taos = new TarArchiveOutputStream(
new FileOutputStream(destFile));
archive(srcFile, taos, BASE_DIR);
taos.flush();
taos.close();
}
示例14: cacheLibrary
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void cacheLibrary (String language, String name)
throws IOException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException,
FTPListParseException
{
File libdir = new File(cachedir, language + "/" + name);
WorkerMain.getLogger().info("Caching Library " + name + " (" + language + ") to " + libdir.getAbsolutePath());
libdir.mkdirs();
DatastoreFtpClient.retrieveLibrary(name, language, libdir);
File libtar = new File(cachedir, language + "/" + name + ".tar.bz2");
TarArchiveOutputStream tar = new TarArchiveOutputStream(new BZip2CompressorOutputStream(new FileOutputStream(libtar)));
tar.setBigNumberMode(BIGNUMBER_POSIX);
tar.setLongFileMode(LONGFILE_POSIX);
addToTar(libdir, tar, "");
tar.close();
}
示例15: tarFolderContent
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
* Tar the content of a given folder to a file.
*
* @param folder the original folder to tar
* @param destinationFile the destination file
* @param exceptionsPaths a list of paths to files or folders which should be excluded from taring
* @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 tarFolderContent(File folder, File destinationFile, HashSet<String> exceptionsPaths, 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);
for (File file : folder.listFiles()) {
String path = file.getAbsolutePath();
if (!exceptionsPaths.contains(path)) {
if (file.isDirectory()) {
addFolderContent(tarOutput, file, waitingHandler);
} else {
addFile(tarOutput, file, waitingHandler);
}
}
}
} finally {
tarOutput.close();
}
} finally {
bos.close();
}
} finally {
fos.close();
}
}