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


Java ArchiveEntry類代碼示例

本文整理匯總了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();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:19,代碼來源:LogArchiver.java

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

示例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");
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:17,代碼來源:RDescriptionUtils.java

示例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;
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:17,代碼來源:DockerOperator.java

示例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);
}
 
開發者ID:tdd-pingis,項目名稱:tdd-pingpong,代碼行數:18,代碼來源:SubmissionPackagingServiceTest.java

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

}
 
開發者ID:tdd-pingis,項目名稱:tdd-pingpong,代碼行數:26,代碼來源:SubmissionPackagingServiceTest.java

示例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;
  }
}
 
開發者ID:DSC-SPIDAL,項目名稱:twister2,代碼行數:31,代碼來源:TarGzipPacker.java

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

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

}
 
開發者ID:Coding,項目名稱:WebIDE-Backend,代碼行數:27,代碼來源:WorkspaceTest.java

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

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

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

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

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

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


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