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


Java ArchiveInputStream.getNextEntry方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.ArchiveInputStream.getNextEntry方法的典型用法代碼示例。如果您正苦於以下問題:Java ArchiveInputStream.getNextEntry方法的具體用法?Java ArchiveInputStream.getNextEntry怎麽用?Java ArchiveInputStream.getNextEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.ArchiveInputStream的用法示例。


在下文中一共展示了ArchiveInputStream.getNextEntry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeOnlyUnZip

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:17,代碼來源:CompressExample.java

示例2: testApache

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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();
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:19,代碼來源:ZipTest.java

示例3: copyArchiveContents

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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();
	}
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:23,代碼來源:ArchiveFileHandler.java

示例4: extractArchive

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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

示例5: extractTarOrGZToTempDir

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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

示例6: locateArchiveEntry

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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

示例7: extractFiles

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
/**
 * Extracts the given archive file into the given directory
 *
 * @param sourceArchive        Archive to extract
 * @param destinationDirectory Directory to extract archive to
 */
private static void extractFiles(File sourceArchive, File destinationDirectory) {
    ArchiveInputStream archiveInputStream = null;
    try {
        archiveInputStream = createArchiveInputStream(sourceArchive);
        ArchiveEntry zipEntry;
        while ((zipEntry = archiveInputStream.getNextEntry()) != null) {
            //Validate entry name before extracting
            String validatedEntryName = validateEntryName(zipEntry.getName());

            if (StringUtils.isNotBlank(validatedEntryName)) {
                extractFile(sourceArchive, destinationDirectory, archiveInputStream, validatedEntryName,
                        zipEntry.getLastModifiedDate(), zipEntry.isDirectory());
            }
        }

    } catch (IOException ioe) {
        throw new RuntimeException("Error while extracting " + sourceArchive.getPath(), ioe);
    } finally {
        IOUtils.closeQuietly(archiveInputStream);
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:28,代碼來源:ZipUtils.java

示例8: buildArchiveEntriesTree

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
/**
 * build archive entries tree from archive data
 * @return archive entries tree instance
 */
private ArchiveEntriesTree buildArchiveEntriesTree() {
    ArchiveEntriesTree tree = new ArchiveEntriesTree();
    String repoKey = getRepoKey();
    ArchiveInputStream archiveInputStream = null;
    try {
        ArchiveEntry archiveEntry;
        // create repo path
        RepoPath repositoryPath = InternalRepoPathFactory.create(repoKey, getPath());
        archiveInputStream = getRepoService().archiveInputStream(repositoryPath);
        while ((archiveEntry = archiveInputStream.getNextEntry()) != null) {
            tree.insert(InfoFactoryHolder.get().createArchiveEntry(archiveEntry), repoKey, getPath());
        }
    } catch (IOException e) {
        log.error("Failed to get  zip Input Stream: " + e.getMessage());
    } finally {
        if (archiveInputStream != null) {
            IOUtils.closeQuietly(archiveInputStream);
        }
        return tree;
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:26,代碼來源:JunctionNode.java

示例9: addDicomFiles

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private static void addDicomFiles(ArchiveInputStream in, ArchiveOutput out, int[] counter) throws Throwable {
	ArchiveEntry ae = in.getNextEntry();
	while (ae != null) {
		if (!ae.isDirectory()) {
			String dicomFileName = String.format("%08d.dcm", counter[0] + 1);
			File tf = PluginTask.createTemporaryFile();
			try {
				StreamCopy.copy(in, tf);
				if (DicomFileCheck.isDicomFile(tf)) {
					out.add(DICOM_MIME_TYPE, dicomFileName, tf);
				}
			} finally {
				PluginTask.deleteTemporaryFile(tf);
			}
			counter[0] += 1;
		}
		ae = in.getNextEntry();
	}
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:20,代碼來源:SvcMyTardisDatasetImport.java

示例10: decompress

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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: testHasNextForNoEntry

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
@Test
public void testHasNextForNoEntry(@Mocked final ArchiveInputStream ain) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = null;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:10,代碼來源:TestArchiveInputStreamIterator.java

示例12: testHasNextForOneEntry

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
@Test
public void testHasNextForOneEntry(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = entry; result = null;
        entry.isDirectory(); result = false;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is a item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:13,代碼來源:TestArchiveInputStreamIterator.java

示例13: testHasNextForTwoEntries

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
@Test
public void testHasNextForTwoEntries(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = entry; result = entry; result = null;
        entry.isDirectory(); result = false;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is 1st item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertTrue("Verify there is 2nd item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:15,代碼來源:TestArchiveInputStreamIterator.java

示例14: testHasNextForDirectory

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
@Test
public void testHasNextForDirectory(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = entry; result = entry; result = null;
        entry.isDirectory(); result = false; result = true;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is 1st item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:13,代碼來源:TestArchiveInputStreamIterator.java

示例15: testHasNextForNameMatch

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的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


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