本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveEntry类的典型用法代码示例。如果您正苦于以下问题:Java ArchiveEntry类的具体用法?Java ArchiveEntry怎么用?Java ArchiveEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArchiveEntry类属于org.apache.commons.compress.archivers包,在下文中一共展示了ArchiveEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeArchivedLogTailToStream
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
zipOutputStream.setEncoding(ZIP_ENCODING);
byte[] content = getTailBytes(logFile);
ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
zipOutputStream.putArchiveEntry(archiveEntry);
zipOutputStream.write(content);
zipOutputStream.closeArchiveEntry();
zipOutputStream.close();
}
示例2: copyArchiveContents
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的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();
}
}
示例3: extractMetadataFromArchive
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
private static Map<String, String> extractMetadataFromArchive(final String archiveType, final InputStream is) {
final ArchiveStreamFactory archiveFactory = new ArchiveStreamFactory();
try (ArchiveInputStream ais = archiveFactory.createArchiveInputStream(archiveType, is)) {
ArchiveEntry entry = ais.getNextEntry();
while (entry != null) {
if (!entry.isDirectory() && DESCRIPTION_FILE_PATTERN.matcher(entry.getName()).matches()) {
return parseDescriptionFile(ais);
}
entry = ais.getNextEntry();
}
}
catch (ArchiveException | IOException e) {
throw new RException(null, e);
}
throw new IllegalStateException("No metadata file found");
}
示例4: unTar
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
private boolean unTar(TarArchiveInputStream tarIn, String outputDir) throws IOException {
ArchiveEntry entry;
boolean newFile = false;
while ((entry = tarIn.getNextEntry()) != null) {
File tmpFile = new File(outputDir + "/" + entry.getName());
newFile = tmpFile.createNewFile();
OutputStream out = new FileOutputStream(tmpFile);
int length;
byte[] b = new byte[2048];
while ((length = tarIn.read(b)) != -1)
out.write(b, 0, length);
out.close();
}
tarIn.close();
return newFile;
}
示例5: packageContainsAllTemplateFiles
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
@Test
public void packageContainsAllTemplateFiles() throws ArchiveException, IOException {
// Create a package with only template files
byte[] packaged = packagingService.packageSubmission(new HashMap<>());
createStreams(packaged);
ArchiveEntry entry = inputArchive.getNextEntry();
Set<String> foundEntries = new HashSet<>();
for (; entry != null; entry = inputArchive.getNextEntry()) {
assertNotEquals(0, entry.getSize());
foundEntries.add(entry.getName());
}
assertEquals(templateEntries, foundEntries);
}
示例6: testAdditionalFiles
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
@Test
public void testAdditionalFiles() throws IOException, ArchiveException {
Map<String, byte[]> randomFiles = generateRandomFiles(NUM_RANDOM_FILES);
byte[] packaged = packagingService.packageSubmission(randomFiles);
createStreams(packaged);
ArchiveEntry entry = inputArchive.getNextEntry();
for (; entry != null; entry = inputArchive.getNextEntry()) {
// Skip template files
if (templateEntries.contains(entry.getName())) {
continue;
}
assertTrue(randomFiles.containsKey(entry.getName()));
byte[] expectedContent = randomFiles.get(entry.getName());
byte[] actualContent = new byte[(int) entry.getSize()];
inputArchive.read(actualContent);
assertArrayEquals(expectedContent, actualContent);
}
}
示例7: addTarGzipToArchive
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
/**
* given tar.gz file will be copied to this tar.gz file.
* all files will be transferred to new tar.gz file one by one.
* original directory structure will be kept intact
*
* @param tarGzipFile the archive file to be copied to the new archive
*/
public boolean addTarGzipToArchive(String tarGzipFile) {
try {
// construct input stream
InputStream fin = Files.newInputStream(Paths.get(tarGzipFile));
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzIn);
// copy the existing entries from source gzip file
ArchiveEntry nextEntry;
while ((nextEntry = tarInputStream.getNextEntry()) != null) {
tarOutputStream.putArchiveEntry(nextEntry);
IOUtils.copy(tarInputStream, tarOutputStream);
tarOutputStream.closeArchiveEntry();
}
tarInputStream.close();
return true;
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive File can not be added: " + tarGzipFile, ioe);
return false;
}
}
示例8: untar
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
public static List<String> untar(FileInputStream input, String targetPath) throws IOException {
TarArchiveInputStream tarInput = new TarArchiveInputStream(input);
ArrayList<String> result = new ArrayList<String>();
ArchiveEntry entry;
while ((entry = tarInput.getNextEntry()) != null) {
File destPath=new File(targetPath,entry.getName());
result.add(destPath.getPath());
if (!entry.isDirectory()) {
FileOutputStream fout=new FileOutputStream(destPath);
final byte[] buffer=new byte[8192];
int n=0;
while (-1 != (n=tarInput.read(buffer))) {
fout.write(buffer,0,n);
}
fout.close();
}
else {
destPath.mkdir();
}
}
tarInput.close();
return result;
}
示例9: assertEntry
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
private static void assertEntry(File file, String name) {
boolean exist = false;
try (TarArchiveInputStream tar = new TarArchiveInputStream(
new GzipCompressorInputStream(
new FileInputStream(file)))) {
ArchiveEntry entry;
while ((entry = tar.getNextEntry()) != null) {
if (entry.getName().equals(name)) {
exist = true;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
if (!exist) {
fail("zip entry " + name + " not exist!");
}
}
示例10: readTap
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
private void readTap(TestHarnessReportBuilder builder, ArchiveInputStream archive, ArchiveEntry entry) {
BufferedReader br = new BufferedReader(new InputStreamReader(archive));
TestDetailBuilder detailBuilder = TestDetail.builder();
detailBuilder.filePath(entry.getName());
br.lines().forEach(line -> {
if (line.startsWith("ok ")) {
detailBuilder.ok();
} else if (line.startsWith("not ok ")) {
detailBuilder.failed();
} else if (line.startsWith("1..")) {
Matcher m = tapNumberOfTests.matcher(line);
if (m.matches()) {
detailBuilder.total(Integer.valueOf(m.group(1)));
}
}
});
TestDetail detail = detailBuilder.build();
if (detail.getNumberOfTests() > 0) {
builder.addTestDetail(detail);
} else {
log.info("Did not recognize TAP or tests skipped completely: " + detail.getFilePath());
}
}
示例11: exportFolder
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
@Override
public byte[] exportFolder(Folder folder) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
String xml = createXStream().toXML(folder);
byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
zipOutputStream.putArchiveEntry(zipEntryDesign);
zipOutputStream.write(xmlBytes);
try {
zipOutputStream.closeArchiveEntry();
} catch (Exception ex) {
throw new RuntimeException(String.format("Exception occurred while exporting folder %s.", folder.getName()));
}
zipOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
示例12: exportEntitiesToZIP
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
@Override
public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) {
String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes);
try {
zipOutputStream.putArchiveEntry(singleDesignEntry);
zipOutputStream.write(jsonBytes);
zipOutputStream.closeArchiveEntry();
} catch (Exception e) {
throw new RuntimeException("Error on creating zip archive during entities export", e);
} finally {
IOUtils.closeQuietly(zipOutputStream);
}
return byteArrayOutputStream.toByteArray();
}
示例13: getArchiveInputStream
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的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());
}
示例14: validateSizeInformation
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
/**
* Throws an exception if the size is unknown for a stored entry
* that is written to a non-seekable output or the entry is too
* big to be written without Zip64 extra but the mode has been set
* to Never.
*/
private void validateSizeInformation(Zip64Mode effectiveMode)
throws ZipException {
// Size/CRC not required if RandomAccessFile is used
if (entry.entry.getMethod() == STORED && raf == null) {
if (entry.entry.getSize() == ArchiveEntry.SIZE_UNKNOWN) {
throw new ZipException("uncompressed size is required for"
+ " STORED method when not writing to a"
+ " file");
}
if (entry.entry.getCrc() == -1) {
throw new ZipException("crc checksum is required for STORED"
+ " method when not writing to a file");
}
entry.entry.setCompressedSize(entry.entry.getSize());
}
if ((entry.entry.getSize() >= ZIP64_MAGIC
|| entry.entry.getCompressedSize() >= ZIP64_MAGIC)
&& effectiveMode == Zip64Mode.Never) {
throw new Zip64RequiredException(Zip64RequiredException
.getEntryTooBigMessage(entry.entry));
}
}
示例15: extractArchive
import org.apache.commons.compress.archivers.ArchiveEntry; //导入依赖的package包/类
private static void extractArchive(final File destination, final ArchiveInputStream archiveInputStream)
throws IOException {
final int BUFFER_SIZE = 8192;
ArchiveEntry entry = archiveInputStream.getNextEntry();
while (entry != null) {
final File destinationFile = new File(destination, entry.getName());
if (entry.isDirectory()) {
destinationFile.mkdir();
} else {
destinationFile.getParentFile().mkdirs();
try (final OutputStream fileOutputStream = new FileOutputStream(destinationFile)) {
final byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = archiveInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
}
}
entry = archiveInputStream.getNextEntry();
}
}