本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveOutputStream.finish方法的具体用法?Java TarArchiveOutputStream.finish怎么用?Java TarArchiveOutputStream.finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
的用法示例。
在下文中一共展示了TarArchiveOutputStream.finish方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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();
}
示例3: 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());
}
示例4: 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();
GzipCompressorOutputStream cos = new GzipCompressorOutputStream(baos);
TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
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();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例5: 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();
BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos);
TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
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();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例6: 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();
XZCompressorOutputStream cos = new XZCompressorOutputStream(baos);
TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
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();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例7: createTar
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
* Creates the tar file with the created JRE for sending to the roborio
*/
private void createTar() {
File tgzFile = new File("." + File.separator + Arguments.JRE_DEFAULT_NAME);
File tgzMd5File = new File(tgzFile.getPath() + ".md5");
if (tgzFile.exists()) {
tgzFile.delete();
m_logger.debug("Removed the old tgz file");
}
if (tgzMd5File.exists()) {
tgzMd5File.delete();
m_logger.debug("Removed the old md5 file");
}
try {
m_logger.debug("Starting zip");
tgzFile.createNewFile();
TarArchiveOutputStream tgzStream = new TarArchiveOutputStream(new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream(tgzFile))));
addFileToTarGz(tgzStream, m_jreLocation, "");
tgzStream.finish();
tgzStream.close();
m_logger.debug("Finished zip, starting md5 hash");
Platform.runLater(() -> fileLabel.setText("Generating md5 hash"));
String md5Hash = MainApp.hashFile(tgzFile);
OutputStream md5Out = new BufferedOutputStream(new FileOutputStream(tgzMd5File));
md5Out.write(md5Hash.getBytes());
md5Out.flush();
md5Out.close();
m_logger.debug("Finished md5 hash, hash is " + md5Hash);
final boolean interrupted = Thread.interrupted();
// Show the connect roboRio screen
Platform.runLater(() -> {
if (!interrupted) {
m_args.setArgument(Arguments.Argument.JRE_TAR, tgzFile.getAbsolutePath());
moveNext(Arguments.Controller.CONNECT_ROBORIO_CONTROLLER);
}
});
} catch (IOException | NoSuchAlgorithmException e) {
m_logger.error("Could not create the tar gz file. Do we have write permissions to the current working directory?", e);
showErrorScreen(e);
}
}
示例8: disposeContainer
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
@Override
protected void disposeContainer(TarArchiveOutputStream container) throws IOException {
container.finish();
}