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


Java ArchiveInputStream類代碼示例

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


ArchiveInputStream類屬於org.apache.commons.compress.archivers包,在下文中一共展示了ArchiveInputStream類的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: extractMetadataFromArchive

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入依賴的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");
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:17,代碼來源:RDescriptionUtils.java

示例5: readTap

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

示例6: readMetaYaml

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void readMetaYaml(TestHarnessReport.TestHarnessReportBuilder builder, ArchiveInputStream archive) throws YamlException {
    BufferedReader br = new BufferedReader(new InputStreamReader(archive));
    YamlReader reader = new YamlReader(br);
    Map<String, Object> object = (Map<String, Object>) reader.read(Map.class);
    builder.startTime(getFromMap(object, "start_time"));
    builder.endTime(getFromMap(object, "stop_time"));
    for (Map<String, Object> fileAttr : (List<Map<String, Object>>) object.get("file_attributes")) {
        builder.addTest(
                new Test((String) fileAttr.get("description"), new BigDecimal((String) fileAttr.get("start_time")),
                        new BigDecimal((String) fileAttr.get("end_time"))));
    }
}
 
開發者ID:sonar-perl,項目名稱:sonar-perl,代碼行數:14,代碼來源:TestHarnessArchiveReader.java

示例7: createArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入依賴的package包/類
/**
 * Create a new ArchiveInputStream to read an archive file based on a format
 * parameter.
 * 
 * If format is not set, this method tries to detect file format
 * automatically. In this case, BufferedInputStream is used to wrap
 * FileInputInputStream instance. BufferedInputStream may read a data
 * partially when calling files.nextFile(). However, it doesn't matter
 * because the partial read data should be discarded. And then this method
 * is called again to create a new ArchiveInputStream.
 * 
 * @return a new ArchiveInputStream instance.
 */
ArchiveInputStream createArchiveInputStream(String format, InputStream in)
        throws IOException, ArchiveException {
    ArchiveStreamFactory factory = new ArchiveStreamFactory();
    if (CommonsCompressUtil.isAutoDetect(format)) {
        in = in.markSupported() ? in : new BufferedInputStream(in);
        try {
            return factory.createArchiveInputStream(in);
        } catch (ArchiveException e) {
            throw new IOException(
                    "Failed to detect a file format. Please try to set a format explicitly.",
                    e);
        }
    } else {
        return factory.createArchiveInputStream(format, in);
    }
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:30,代碼來源:CommonsCompressProvider.java

示例8: testArchiveFile

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入依賴的package包/類
@Test
public void testArchiveFile() throws Exception {
    InputStream in = getClass().getResourceAsStream("samples.tar");
    ArchiveInputStream ain = new ArchiveStreamFactory().createArchiveInputStream(in);
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is 1st item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", "1,foo", readContents(it.next()));
    assertTrue("Verify there is 2nd item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", "2,bar", readContents(it.next()));
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());

    // Verify calling after no data.
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:17,代碼來源:TestArchiveInputStreamIterator.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: returnArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入依賴的package包/類
/**
 * return archive input stream
 *
 * @param inputStream - file  input Stream
 * @param archiveSuffix   - archive suffix
 * @return archive input stream
 * @throws IOException
 */
public static ArchiveInputStream returnArchiveInputStream(InputStream inputStream, String archiveSuffix)
        throws IOException {
    if (isZipFamilyArchive(archiveSuffix)) {
        return new ZipArchiveInputStream(inputStream);
    }

    if (isTarArchive(archiveSuffix)) {
        return new TarArchiveInputStream(inputStream);
    }

    if (isTgzFamilyArchive(archiveSuffix) || isGzCompress(archiveSuffix)) {
        return new TarArchiveInputStream(new GzipCompressorInputStream(inputStream));
    }
    return null;
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:24,代碼來源:ZipUtils.java

示例14: 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

示例15: 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


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