本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveOutputStream.closeArchiveEntry方法的典型用法代码示例。如果您正苦于以下问题:Java ArchiveOutputStream.closeArchiveEntry方法的具体用法?Java ArchiveOutputStream.closeArchiveEntry怎么用?Java ArchiveOutputStream.closeArchiveEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.ArchiveOutputStream
的用法示例。
在下文中一共展示了ArchiveOutputStream.closeArchiveEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: copyArchiveContents
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Copies the contents of an archive file to the specified output stream
*
* @param archiveFile the archive file
* @param outputStream the output stream
* @throws IOException error copying the archive contents
*/
private void copyArchiveContents(File archiveFile, ArchiveOutputStream outputStream) throws IOException {
ArchiveInputStream inputStream = this.createArchiveInputStream(archiveFile);
ArchiveEntry entry;
byte[] buffer = new byte[this.bufferSize];
while ((entry = inputStream.getNextEntry()) != null) {
outputStream.putArchiveEntry(entry);
int count;
while ((count = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, count);
}
outputStream.closeArchiveEntry();
}
}
示例4: addFilesToZip
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
OutputStream archiveStream = new FileOutputStream(destination);
ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
Collection<File> fileList = FileUtils.listFiles(source, null, true);
for (File file : fileList) {
String entryName = getEntryName(source, file);
ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
archive.putArchiveEntry(entry);
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
IOUtils.copy(input, archive);
input.close();
archive.closeArchiveEntry();
}
archive.finish();
archiveStream.close();
}
示例5: insertFile
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private static void insertFile(File file, String entryName, ArchiveOutputStream archive) throws IOException {
if (DEFAULT_EXCLUDES.contains(file.getName())) {
logger.debug("Skipping ! [l] {}", entryName);
return;
}
if (file.isFile()) {
ZipArchiveEntry newEntry = new ZipArchiveEntry(entryName);
setExtraFields(file.toPath(), UnixStat.FILE_FLAG, newEntry);
archive.putArchiveEntry(newEntry);
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
IOUtils.copy(input, archive);
input.close();
archive.closeArchiveEntry();
} else {
throw new IOException("Provided file is not a file");
}
}
示例6: 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());
}
示例7: compressArchive
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private static void compressArchive(
final Path pathToCompress,
final ArchiveOutputStream archiveOutputStream,
final ArchiveEntryFactory archiveEntryFactory,
final CompressionType compressionType,
final BuildListener listener)
throws IOException {
final List<File> files = addFilesToCompress(pathToCompress, listener);
LoggingHelper.log(listener, "Compressing directory '%s' as a '%s' archive",
pathToCompress.toString(),
compressionType.name());
for (final File file : files) {
final String newTarFileName = pathToCompress.relativize(file.toPath()).toString();
final ArchiveEntry archiveEntry = archiveEntryFactory.create(file, newTarFileName);
archiveOutputStream.putArchiveEntry(archiveEntry);
try (final FileInputStream fileInputStream = new FileInputStream(file)) {
IOUtils.copy(fileInputStream, archiveOutputStream);
}
archiveOutputStream.closeArchiveEntry();
}
}
示例8: addZipEntry
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Adds an entry to the zip.
*
* @param archiveOutputStream {@code ArchiveOutputStream} to output zip entry to.
* @param filename Name of the file to add to the zip.
* @throws IOException If an error occurs adding the file to the zip.
*/
private void addZipEntry(final ArchiveOutputStream archiveOutputStream, final String filename) throws IOException {
FileInputStream fileInputStream = null;
try {
File file = new File("src/main/resources/" + filename);
ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, filename);
archiveOutputStream.putArchiveEntry(archiveEntry);
fileInputStream = new FileInputStream(file);
IOUtils.copy(fileInputStream, archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unable to create zip entry for file: [{0}]. {1}",
new String[]{filename, e.getMessage()});
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
}
}
示例9: addTargetToArchiveOutputStream
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Add some target to the archive outputstream.
*
* @param target the target to write in the outputstream.
* @param archiveOutputStream the archive outputstream.
* @throws IOException if something goes wrong.
*/
private void addTargetToArchiveOutputStream(Target target, ArchiveOutputStream archiveOutputStream) throws IOException {
Volume targetVolume = target.getVolume();
try (InputStream targetInputStream = targetVolume.openInputStream(target)) {
// get the target infos
final long targetSize = targetVolume.getSize(target);
final byte[] targetContent = new byte[(int) targetSize];
final String targetPath = targetVolume.getPath(target); // relative path
// creates the entry and writes in the archive output stream
ArchiveEntry entry = createArchiveEntry(targetPath, targetSize, targetContent);
archiveOutputStream.putArchiveEntry(entry);
// archiveOutputStream.write(targetContent);
IOUtils.copy(targetInputStream, archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
}
}
示例10: addFilesToZip
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
value = "OBL_UNSATISFIED_OBLIGATION",
justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
try {
@Cleanup
OutputStream archiveStream = new FileOutputStream(zipFile);
@Cleanup
ArchiveOutputStream archive =
new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
for (File fileToAdd : filesToAdd) {
ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
archive.putArchiveEntry(entry);
@Cleanup
BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
IOUtils.copy(input, archive);
archive.closeArchiveEntry();
}
archive.finish();
} catch (ArchiveException e) {
throw new IOException("Issue with creating archive", e);
}
}
示例11: createArchiveEntry
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
* Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File}
* into the new entry.
*
* @param file the file to add to the archive
* @param entryName the name of the archive entry
* @param archive the archive to write to
* @throws IOException when an I/O error occurs during FileInputStream creation or during copying
*/
protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException {
ArchiveEntry entry = archive.createArchiveEntry(file, entryName);
// TODO #23: read permission from file, write it to the ArchiveEntry
archive.putArchiveEntry(entry);
if (!entry.isDirectory()) {
FileInputStream input = null;
try {
input = new FileInputStream(file);
IOUtils.copy(input, archive);
} finally {
IOUtils.closeQuietly(input);
}
}
archive.closeArchiveEntry();
}
示例12: addFile
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private void addFile(ArchiveOutputStream archive, String tarFileName, Path filePath)
throws IOException {
ArchiveEntry archiveEntry = archive.createArchiveEntry(filePath.toFile(), tarFileName);
archive.putArchiveEntry(archiveEntry);
Files.copy(filePath, archive);
archive.closeArchiveEntry();
logger.debug("Added file {} as {}", filePath.toAbsolutePath(), tarFileName);
}
示例13: 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();
}
示例14: 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);
}
示例15: compressFile
import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
protected void compressFile(Path root, Path file, ArchiveOutputStream archiveOutputStream) throws IOException {
try (InputStream inputStream = newInputStream(file)) {
final long size = size(file);
final byte[] content = new byte[(int) size];
final String relativePath = root.relativize(file).toString();
logger.debug("writting " + relativePath + " path in the archive output stream");
ArchiveEntry entry = createArchiveEntry(relativePath, size, content);
archiveOutputStream.putArchiveEntry(entry);
IOUtils.copy(inputStream, archiveOutputStream); //archiveOutputStream.write(content);
archiveOutputStream.closeArchiveEntry();
}
}