Java Code Examples for org.apache.commons.compress.archivers.ArchiveOutputStream#createArchiveEntry()

The following examples show how to use org.apache.commons.compress.archivers.ArchiveOutputStream#createArchiveEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneratorService.java    From vertx-starter with Apache License 2.0 6 votes vote down vote up
private void addFile(Path rootPath, Path filePath, ArchiveOutputStream stream) throws IOException {
  String relativePath = rootPath.relativize(filePath).toString();
  if (relativePath.length() == 0) return;
  String entryName = jarFileWorkAround(leadingDot(relativePath));
  ArchiveEntry entry = stream.createArchiveEntry(filePath.toFile(), entryName);
  if (EXECUTABLES.contains(entryName)) {
    if (entry instanceof ZipArchiveEntry) {
      ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entry;
      zipArchiveEntry.setUnixMode(0744);
    } else if (entry instanceof TarArchiveEntry) {
      TarArchiveEntry tarArchiveEntry = (TarArchiveEntry) entry;
      tarArchiveEntry.setMode(0100744);
    }
  }
  stream.putArchiveEntry(entry);
  if (filePath.toFile().isFile()) {
    try (InputStream i = Files.newInputStream(filePath)) {
      IOUtils.copy(i, stream);
    }
  }
  stream.closeArchiveEntry();
}
 
Example 2
Source File: RemoteApiBasedDockerProvider.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static void addToTar(ArchiveOutputStream tar, File file, String fileNameAndPath) throws IOException {
    if (!file.exists() || !file.canRead()) {
        throw new FileNotFoundException(String.format("Cannot read file %s. Are you sure it exists?",
                file.getAbsolutePath()));
    }
    if (file.isDirectory()) {
        for (File fileInDirectory : file.listFiles()) {
            if (!fileNameAndPath.endsWith("/")) {
                fileNameAndPath = fileNameAndPath + "/";
            }
            addToTar(tar, fileInDirectory, fileNameAndPath + fileInDirectory.getName());
        }
    } else {
        ArchiveEntry entry = tar.createArchiveEntry(file, fileNameAndPath);
        tar.putArchiveEntry(entry);
        try (FileInputStream fis = new FileInputStream(file)) {
            IOUtils.copy(fis, tar);
        }
        tar.closeArchiveEntry();
    }
}
 
Example 3
Source File: TarContainerPacker.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static void includeFile(File file, String entryName,
    ArchiveOutputStream archiveOutput) throws IOException {
  ArchiveEntry entry = archiveOutput.createArchiveEntry(file, entryName);
  archiveOutput.putArchiveEntry(entry);
  try (InputStream input = new FileInputStream(file)) {
    IOUtils.copy(input, archiveOutput);
  }
  archiveOutput.closeArchiveEntry();
}
 
Example 4
Source File: OMDBCheckpointServlet.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private static void includeFile(File file, String entryName,
    ArchiveOutputStream archiveOutputStream)
    throws IOException {
  ArchiveEntry archiveEntry =
      archiveOutputStream.createArchiveEntry(file, entryName);
  archiveOutputStream.putArchiveEntry(archiveEntry);
  try (FileInputStream fis = new FileInputStream(file)) {
    IOUtils.copy(fis, archiveOutputStream);
  }
  archiveOutputStream.closeArchiveEntry();
}