本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveEntry.getName方法的典型用法代码示例。如果您正苦于以下问题:Java ArchiveEntry.getName方法的具体用法?Java ArchiveEntry.getName怎么用?Java ArchiveEntry.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.ArchiveEntry
的用法示例。
在下文中一共展示了ArchiveEntry.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
}
示例4: extractTarOrGZToTempDir
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private boolean extractTarOrGZToTempDir(File nestedTempDir, File tar, String virtualPath) {
ArchiveInputStream tarInputStream = null;
try {
tarInputStream = getArchiveInputStream(tar);
ArchiveEntry entry;
while ((entry = tarInputStream.getNextEntry()) != null) {
String fileName = entry.getName();
if (!entry.isDirectory() && (isCandidateForSha1(virtualPath + "/" + fileName) || isCandidateForExtract(virtualPath + "/" + fileName))) {
byte[] buffer = new byte[(int) entry.getSize()];
tarInputStream.read(buffer, 0, buffer.length);
FileUtils.writeByteArrayToFile(new File(nestedTempDir +"/" + fileName), buffer);
}
}
} catch (IOException e) {
listener.getLogger().println("Failed to extract archive: ["+tar.getAbsolutePath()+"]: " + e.getMessage());
} finally {
IOUtils.closeQuietly(tarInputStream);
}
return nestedTempDir.exists();
}
示例5: locateArchiveEntry
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
/**
* Searches for an entry inside the zip stream by entry path. If there are alternative extensions, will also look
* for entry with alternative extension. The search stops reading the stream when the entry is found, so calling
* read on the stream will read the returned entry. <p/>
* The zip input stream doesn't support mark/reset so once this method is used you cannot go back - either the
* stream was fully read (when entry is not found) or the stream was read until the current entry.
*
* @param zis The ar input stream
* @param entryPath The entry path to search for
* @param alternativeExtensions List of alternative file extensions to try if the main entry path is not found.
* @return The entry if found, null otherwise
* @throws IOException On failure to read the stream
*/
public static ArchiveEntry locateArchiveEntry(ArchiveInputStream zis, String entryPath,
List<String> alternativeExtensions)
throws IOException {
ArchiveEntry archiveEntry;
while ((archiveEntry = zis.getNextEntry()) != null) {
String zipEntryName = archiveEntry.getName();
if (zipEntryName.equals(entryPath)) {
return archiveEntry;
} else if (alternativeExtensions != null) {
String basePath = PathUtils.stripExtension(entryPath);
for (String alternativeExtension : alternativeExtensions) {
String alternativeSourcePath = basePath + "." + alternativeExtension;
if (zipEntryName.equals(alternativeSourcePath)) {
return archiveEntry;
}
}
}
}
return null;
}
示例6: ArchiveEntryImpl
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
public ArchiveEntryImpl(@Nonnull ArchiveEntry... entries) {
if (entries.length == 0) {
throw new IllegalArgumentException("Cannot create ZipEntryInfo without a ZipEntry!");
}
ArchiveEntry entry = entries[entries.length - 1];
if (entries.length > 1) {
StringBuilder fullPath = new StringBuilder();
for (int i = 0; i < entries.length; i++) {
fullPath.append(entries[i].getName());
if (i != entries.length - 1) {
fullPath.append(RepoPath.ARCHIVE_SEP).append('/');
}
}
this.path = fullPath.toString();
} else {
this.path = entry.getName();
}
this.name = PathUtils.getFileName(entry.getName());
this.time = entry.getLastModifiedDate().getTime();
this.size = entry.getSize();
this.directory = entry.isDirectory();
}
示例7: untar
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
public static void untar(
InputStream tar,
File parentDir
) throws IOException {
TarArchiveInputStream tin = new TarArchiveInputStream(tar);
ArchiveEntry e;
while ((e = tin.getNextEntry()) != null) {
File f = new File(parentDir, e.getName());
f.setLastModified(e.getLastModifiedDate().getTime());
f.getParentFile().mkdirs();
if (e.isDirectory()) {
f.mkdir();
continue;
}
long size = e.getSize();
checkFileSize(size);
try (OutputStream out = new FileOutputStream(f)) {
/* TarInputStream pretends each
entry's EOF is the stream's EOF */
IOUtils.copy(tin, out);
}
}
}
示例8: parseEntry
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private boolean parseEntry(ArchiveInputStream archive, ArchiveEntry entry, EmbeddedExtractor extractor, Record record) {
String name = entry.getName();
if (archive.canReadEntryData(entry)) {
Record entrydata = new Record(); // TODO: or pass myself?
//Record entrydata = record.copy();
// For detectors to work, we need a mark/reset supporting
// InputStream, which ArchiveInputStream isn't, so wrap
TemporaryResources tmp = new TemporaryResources();
try {
TikaInputStream tis = TikaInputStream.get(archive, tmp);
return extractor.parseEmbedded(tis, entrydata, name, getChild());
} finally {
try {
tmp.dispose();
} catch (TikaException e) {
LOG.warn("Cannot dispose of tmp Tika resources", e);
}
}
} else {
return false;
}
}
示例9: extract
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
/**
* Extracts a Zip Entry from an archive to a directory
*
* @param zis
* Archive
* @param entry
* Zip Entry
* @param targetDir
* Directory to extract file to
* @throws IOException
* in case of error
*/
protected static void extract(ZipArchiveInputStream zis, ArchiveEntry entry, File targetDir, boolean mkdirs) throws IOException {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
File targetFile = new File(targetDir.getAbsolutePath() + File.separator + entry.getName());
if (mkdirs) {
targetFile.getParentFile().mkdirs();
}
fos = new FileOutputStream(targetFile);
bos = new BufferedOutputStream(fos, BUFFER);
int count;
byte[] data = new byte[BUFFER];
while ((count = zis.read(data, 0, BUFFER)) != -1) {
bos.write(data, 0, count);
}
} finally {
IOUtils.closeQuietly(bos);
IOUtils.closeQuietly(fos);
}
}
示例10: decompress
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static void decompress(ArchiveInputStream archiveInputStream, File outputFile) throws IOException {
int entries = 0;
ArchiveEntry entry;
while ((entry = archiveInputStream.getNextEntry()) != null) {
log.log(LogLevel.DEBUG, "Unpacking " + entry.getName());
File outFile = new File(outputFile, entry.getName());
if (entry.isDirectory()) {
if (!(outFile.exists() && outFile.isDirectory())) {
log.log(LogLevel.DEBUG, "Creating dir: " + outFile.getAbsolutePath());
if (!outFile.mkdirs()) {
log.log(LogLevel.WARNING, "Could not create dir " + entry.getName());
}
}
} else {
// Create parent dir if necessary
File parent = new File(outFile.getParent());
if (!parent.exists() && !parent.mkdirs()) {
log.log(LogLevel.WARNING, "Could not create dir " + parent.getAbsolutePath());
}
FileOutputStream fos = new FileOutputStream(outFile);
ByteStreams.copy(archiveInputStream, fos);
fos.close();
}
entries++;
}
if (entries == 0) {
log.log(LogLevel.WARNING, "Not able to read any entries from " + outputFile.getName());
}
}
示例11: decompressInto
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private void decompressInto(File application) throws IOException {
log.log(LogLevel.DEBUG, "Application is in " + application.getAbsolutePath());
int entries = 0;
ArchiveEntry entry;
while ((entry = ais.getNextEntry()) != null) {
log.log(LogLevel.DEBUG, "Unpacking " + entry.getName());
File outFile = new File(application, entry.getName());
// FIXME/TODO: write more tests that break this logic. I have a feeling it is not very robust.
if (entry.isDirectory()) {
if (!(outFile.exists() && outFile.isDirectory())) {
log.log(LogLevel.DEBUG, "Creating dir: " + outFile.getAbsolutePath());
boolean res = outFile.mkdirs();
if (!res) {
log.log(LogLevel.WARNING, "Could not create dir " + entry.getName());
}
}
} else {
log.log(LogLevel.DEBUG, "Creating output file: " + outFile.getAbsolutePath());
// Create parent dir if necessary
String parent = outFile.getParent();
new File(parent).mkdirs();
FileOutputStream fos = new FileOutputStream(outFile);
ByteStreams.copy(ais, fos);
fos.close();
}
entries++;
}
if (entries == 0) {
log.log(LogLevel.WARNING, "Not able to read any entries from " + application.getName());
}
}
示例12: matchName
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private boolean matchName(ArchiveEntry entry, String regex) {
String name = entry.getName();
if(regex == null || regex.equals("")){
return true;
} else if(name == null) {
return false;
} else {
return name.matches(regex);
}
}
示例13: testHasNextForNameMatch
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
@Test
public void testHasNextForNameMatch(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
new NonStrictExpectations() {{
ain.getNextEntry(); result = entry; result = entry; result = entry; result = null;
entry.getName(); result = "first.csv"; result = "second.txt"; result = "third.csv";
}};
ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain, ".*\\.csv");
assertTrue("Verify 1st file match", it.hasNext());
assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
assertTrue("Verify 3rd file match", it.hasNext());
assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
assertFalse("Veryfy no more entry because second.txt is skipped.", it.hasNext());
assertNull("Verify there is no stream.", it.next());
}
示例14: unarchive
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static List<File> unarchive(File inputFile, File outputDir)
throws Throwable {
InputStream is = new BufferedInputStream(new FileInputStream(inputFile));
ArchiveInputStream ais = null;
List<File> ofs = new ArrayList<File>();
try {
ais = new ArchiveStreamFactory().createArchiveInputStream(is);
ArchiveEntry ae = ais.getNextEntry();
while (ae != null) {
if (!ae.isDirectory()) {
File of = new File(outputDir, ae.getName());
OutputStream os = new FileOutputStream(of);
try {
IOUtils.copy(ais, os);
} finally {
os.close();
}
ofs.add(of);
}
ae = ais.getNextEntry();
}
} catch (Throwable e) {
// failed to extract
} finally {
is.close();
if (ais != null) {
ais.close();
}
}
if (ofs.isEmpty()) {
return null;
} else {
return ofs;
}
}
示例15: parseEntry
import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private void parseEntry(
ArchiveInputStream archive, ArchiveEntry entry,
EmbeddedDocumentExtractor extractor, XHTMLContentHandler xhtml)
throws SAXException, IOException, TikaException {
String name = entry.getName();
if (archive.canReadEntryData(entry)) {
Metadata entrydata = new Metadata();
if (name != null && name.length() > 0) {
entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "class", "class", "CDATA", "embedded");
attributes.addAttribute("", "id", "id", "CDATA", name);
xhtml.startElement("div", attributes);
xhtml.endElement("div");
entrydata.set(Metadata.EMBEDDED_RELATIONSHIP_ID, name);
}
if (extractor.shouldParseEmbedded(entrydata)) {
// For detectors to work, we need a mark/reset supporting
// InputStream, which ArchiveInputStream isn't, so wrap
TemporaryResources tmp = new TemporaryResources();
try {
TikaInputStream tis = TikaInputStream.get(archive, tmp);
extractor.parseEmbedded(tis, xhtml, entrydata, true);
} finally {
tmp.dispose();
}
}
} else if (name != null && name.length() > 0) {
xhtml.element("p", name);
}
}