當前位置: 首頁>>代碼示例>>Java>>正文


Java ArchiveEntry.getName方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:17,代碼來源:DockerOperator.java

示例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;
}
 
開發者ID:BloomBooks,項目名稱:BloomReader,代碼行數:25,代碼來源:IOUtilities.java

示例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();
    }
}
 
開發者ID:awslabs,項目名稱:aws-codepipeline-plugin-for-jenkins,代碼行數:26,代碼來源:ExtractionTools.java

示例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();
}
 
開發者ID:jenkinsci,項目名稱:checkmarx-plugin,代碼行數:24,代碼來源:OSAScanner.java

示例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;
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:34,代碼來源:ZipUtils.java

示例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();
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:25,代碼來源:ArchiveEntryImpl.java

示例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);
        }
    }
}
 
開發者ID:winstonli,項目名稱:writelatex-git-bridge,代碼行數:24,代碼來源:Tar.java

示例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;
  } 
}
 
開發者ID:cloudera,項目名稱:cdk,代碼行數:24,代碼來源:UnpackBuilder.java

示例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);
    }

}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:38,代碼來源:ZipFileUtil.java

示例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());
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:30,代碼來源:CompressedFileReference.java

示例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());
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:34,代碼來源:CompressedApplicationInputStream.java

示例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);
    }
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:11,代碼來源:ArchiveInputStreamIterator.java

示例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());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:15,代碼來源:TestArchiveInputStreamIterator.java

示例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;
    }
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:36,代碼來源:DarisTranscodeImpl.java

示例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);
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:33,代碼來源:PackageParser.java


注:本文中的org.apache.commons.compress.archivers.ArchiveEntry.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。