本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ArchiveOutputStream.close方法的具体用法?Java ArchiveOutputStream.close怎么用?Java ArchiveOutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.ArchiveOutputStream
的用法示例。
在下文中一共展示了ArchiveOutputStream.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testApache
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public void testApache() throws IOException, ArchiveException {
log.debug("testApache()");
File zip = File.createTempFile("apache_", ".zip");
// Create zip
FileOutputStream fos = new FileOutputStream(zip);
ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
aos.closeArchiveEntry();
aos.close();
// Read zip
FileInputStream fis = new FileInputStream(zip);
ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
assertEquals(zae.getName(), "coñeta");
ais.close();
}
示例2: makeOnlyZip
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public static void makeOnlyZip() throws IOException, ArchiveException{
File f1 = new File("D:/compresstest.txt");
File f2 = new File("D:/test1.xml");
final OutputStream out = new FileOutputStream("D:/中文名字.zip");
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
IOUtils.copy(new FileInputStream(f1), os);
os.closeArchiveEntry();
os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
IOUtils.copy(new FileInputStream(f2), os);
os.closeArchiveEntry();
os.close();
}
示例3: getArchiveInputStream
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private InputStream getArchiveInputStream(String format, String ...resourceFiles)
throws ArchiveException, URISyntaxException, IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ArchiveStreamFactory factory = new ArchiveStreamFactory();
ArchiveOutputStream aout = factory.createArchiveOutputStream(format, bout);
for (String resource : resourceFiles) {
File f = new File(getClass().getResource(resource).toURI());
ArchiveEntry entry = aout.createArchiveEntry(f, resource);
aout.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(f),aout);
aout.closeArchiveEntry();
}
aout.finish();
aout.close();
return new ByteArrayInputStream(bout.toByteArray());
}
示例4: createPackageZip
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Creates the {@code CRX} package definition.
*
* @param packageName Name of the package to create.
*/
public final void createPackageZip(final String packageName) {
try {
ArchiveOutputStream archiveOutputStream =
new ZipArchiveOutputStream(new File("src/main/resources/" + packageName + ".zip"));
addZipEntry(archiveOutputStream, "META-INF/vault/definition/.content.xml");
addZipEntry(archiveOutputStream, "META-INF/vault/config.xml");
addZipEntry(archiveOutputStream, "META-INF/vault/filter.xml");
addZipEntry(archiveOutputStream, "META-INF/vault/nodetypes.cnd");
addZipEntry(archiveOutputStream, "META-INF/vault/properties.xml");
addZipEntry(archiveOutputStream, "jcr_root/.content.xml");
archiveOutputStream.finish();
archiveOutputStream.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unable to create package zip: {0}", e.getMessage());
}
}
示例5: writeEventLogsToHttpServletResponse
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public void writeEventLogsToHttpServletResponse(final HttpServletResponse httpResponse, final Iterable<String> fileNames) throws IOException {
// First, we check if the given paths are in the log path
final Set<String> eventLogs = Sets.newHashSet(listEventLogsNameInThePath());
ArchiveOutputStream outputStream = null;
try {
for (final String fileName : fileNames) {
if (eventLogs.contains(fileName) && new File(getLogPathDirectory(), fileName).exists()) {
outputStream = writeEventLogToHttpServletResponse(httpResponse, fileName, outputStream);
}
}
} finally {
if (outputStream != null) {
outputStream.close();
}
}
if (outputStream == null) {
// No file were appended
httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
final PrintWriter writer = httpResponse.getWriter();
writer.write("No log available at the moment.");
}
}
示例6: makeZip
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public static void makeZip() throws IOException, ArchiveException{
File f1 = new File("D:/compresstest.txt");
File f2 = new File("D:/test1.xml");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//ArchiveOutputStream ostemp = new ArchiveStreamFactory().createArchiveOutputStream("zip", baos);
ZipArchiveOutputStream ostemp = new ZipArchiveOutputStream(baos);
ostemp.setEncoding("GBK");
ostemp.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
IOUtils.copy(new FileInputStream(f1), ostemp);
ostemp.closeArchiveEntry();
ostemp.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
IOUtils.copy(new FileInputStream(f2), ostemp);
ostemp.closeArchiveEntry();
ostemp.finish();
ostemp.close();
// final OutputStream out = new FileOutputStream("D:/testcompress.zip");
final OutputStream out = new FileOutputStream("D:/中文名字.zip");
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
os.putArchiveEntry(new ZipArchiveEntry("打包.zip"));
baos.writeTo(os);
os.closeArchiveEntry();
baos.close();
os.finish();
os.close();
}
示例7: createArchiveFile
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private static void createArchiveFile(ArchiveOutputStream archiveOutputStream, File baseDir, List<File> inputFiles) throws IOException {
inputFiles.forEach(file -> {
try {
writeFileToTar(archiveOutputStream, baseDir, file);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
archiveOutputStream.close();
}
示例8: createArchiveFile
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public static File createArchiveFile(ArchiveOutputStream taos, File outFile) throws IOException {
File app = new File("src/test/resources/deploy/validapp");
writeFileToTar(taos, new File(app, "services.xml"));
writeFileToTar(taos, new File(app, "hosts.xml"));
writeFileToTar(taos, new File(app, "deployment.xml"));
taos.close();
return outFile;
}
示例9: require_that_valid_tar_application_in_subdir_can_be_unpacked
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@Test
public void require_that_valid_tar_application_in_subdir_can_be_unpacked() throws IOException {
File outFile = File.createTempFile("testapp", ".tar.gz");
ArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(outFile)));
File app = new File("src/test/resources/deploy/validapp");
File file = new File(app, "services.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
file = new File(app, "hosts.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
file = new File(app, "deployment.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
archiveOutputStream.close();
CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(outFile))));
File outApp = unpacked.decompress();
assertThat(outApp.getName(), is("application")); // gets the name of the subdir
assertTestApp(outApp);
}
示例10: compress
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@Override
public Target compress(Target... targets) throws IOException {
Target compressTarget = null;
Path compressFile = null;
ArchiveOutputStream archiveOutputStream = null;
try {
for (Target target : targets) {
// get target volume
final Volume targetVolume = target.getVolume();
// gets the target infos
final String targetName = targetVolume.getName(target);
final String targetDir = targetVolume.getParent(target).toString();
final boolean isTargetFolder = targetVolume.isFolder(target);
if (compressFile == null) {
// create compress file
String compressFileName = (targets.length == 1) ? targetName : getArchiveName();
compressFile = Paths.get(targetDir, compressFileName + getExtension());
// creates a new compress file to not override if already exists
// if you do not want this behavior, just comment this line
compressFile = createFile(true, compressFile.getParent(), compressFile);
compressTarget = targetVolume.fromPath(compressFile.toString());
// open streams to write the compress target contents and auto close it
archiveOutputStream = createArchiveOutputStream(compressFile);
}
if (isTargetFolder) {
// compress target directory
compressDirectory(target, archiveOutputStream);
} else {
// compress target file
compressFile(target, archiveOutputStream);
}
}
} finally {
// close streams
if (archiveOutputStream != null) {
archiveOutputStream.finish();
archiveOutputStream.close();
}
}
return compressTarget;
}
示例11: compress
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Default compress implementation used by .tar and .tgz
*
* @return the compress archive target.
*/
@Override
public Target compress(Target... targets) throws IOException {
Target compressTarget = null;
OutputStream outputStream = null;
BufferedOutputStream bufferedOutputStream = null;
ArchiveOutputStream archiveOutputStream = null;
try {
for (Target target : targets) {
// get target volume
final Volume targetVolume = target.getVolume();
// gets the target infos
final String targetName = targetVolume.getName(target);
final String targetDir = targetVolume.getParent(target).toString();
final boolean isTargetFolder = targetVolume.isFolder(target);
if (compressTarget == null) {
// create compress file
String compressFileName = (targets.length == 1) ? targetName : getArchiveName();
Path compressFile = Paths.get(targetDir, compressFileName + getExtension());
// creates a new compress file to not override if already exists
// if you do not want this behavior, just comment this line
compressFile = createFile(true, compressFile.getParent(), compressFile);
compressTarget = targetVolume.fromPath(compressFile.toString());
// open streams to write the compress target contents and auto close it
outputStream = targetVolume.openOutputStream(compressTarget);
bufferedOutputStream = new BufferedOutputStream(outputStream);
archiveOutputStream = createArchiveOutputStream(bufferedOutputStream);
}
if (isTargetFolder) {
// compress target directory
compressDirectory(target, archiveOutputStream);
} else {
// compress target file
compressFile(target, archiveOutputStream);
}
}
} finally {
// close streams
if (archiveOutputStream != null) {
archiveOutputStream.finish();
archiveOutputStream.close();
}
if (bufferedOutputStream != null) {
bufferedOutputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
return compressTarget;
}