Source:
<code>public static void tarDirectory(Path outputFile, Path inputDirectory, List<String> pathPrefixesToExclude) throws IOException { System.out.println("Creating archive at: " + outputFile); <START> boolean fullTarArchive = Boolean.valueOf(System.getenv(FULL_TAR_ARCHIVE)); <END> if (fullTarArchive) System.out.println("Required full archive creation"); Collection<String> collectionPathPrefixesToExclude = CollectionUtils.emptyIfNull(pathPrefixesToExclude); FileOutputStream dest = new FileOutputStream(outputFile.toFile()); final Path outputFileAbsolute = outputFile.normalize().toAbsolutePath(); final Path inputDirectoryAbsolute = inputDirectory.normalize().toAbsolutePath(); final int inputPathLength = inputDirectoryAbsolute.toString().length(); try (TarOutputStream out = new TarOutputStream(new BufferedOutputStream(dest))) { Files.walk(inputDirectoryAbsolute).forEach(entry -> { if (Files.isDirectory(entry)) return; if (entry.equals(outputFileAbsolute)) return; try { String relativeName = entry.toString().substring(inputPathLength + 1); if (!fullTarArchive && collectionPathPrefixesToExclude.stream().anyMatch(pathPrefixToExclude -> relativeName.startsWith(pathPrefixToExclude))) return; out.putNextEntry(new TarEntry(entry.toFile(), relativeName)); BufferedInputStream origin = new BufferedInputStream(new FileInputStream(entry.toFile())); int count; byte data[] = new byte[2048]; while ((count = origin.read(data)) != -1) { out.write(data, 0, count); } out.flush(); origin.close(); } catch (IOException e) { System.err.println("Failed to add tar entry due to: " + e.getMessage()); e.printStackTrace(); } }); } }</code><technical_language>this works, placement of code feels strange me. a generic TarUtil a boolean FULL_TAR_ARCHIVE property ignore of parameters based this value? feels this logic in caller. Also, assuming leave System.out.println statements in. :)</technical_language>

Target:
public static void tarDirectory(Path outputFile, Path inputDirectory, List<String> pathPrefixesToExclude) throws IOException { LOG.info("Creating archive at: " + outputFile); Collection<String> collectionPathPrefixesToExclude = CollectionUtils.emptyIfNull(pathPrefixesToExclude); FileOutputStream dest = new FileOutputStream(outputFile.toFile()); final Path outputFileAbsolute = outputFile.normalize().toAbsolutePath(); final Path inputDirectoryAbsolute = inputDirectory.normalize().toAbsolutePath(); final int inputPathLength = inputDirectoryAbsolute.toString().length(); try (TarOutputStream out = new TarOutputStream(new BufferedOutputStream(dest))) { Files.walk(inputDirectoryAbsolute).forEach(entry -> { if (Files.isDirectory(entry)) return; if (entry.equals(outputFileAbsolute)) return; try { String relativeName = entry.toString().substring(inputPathLength + 1); if (collectionPathPrefixesToExclude.stream().anyMatch(pathPrefixToExclude -> relativeName.startsWith(pathPrefixToExclude))) return; out.putNextEntry(new TarEntry(entry.toFile(), relativeName)); BufferedInputStream origin = new BufferedInputStream(new FileInputStream(entry.toFile())); int count; byte data[] = new byte[2048]; while ((count = origin.read(data)) != -1) { out.write(data, 0, count); } out.flush(); origin.close(); } catch (IOException e) { LOG.severe("Failed to add tar entry due to: " + e.getMessage()); e.printStackTrace(); } }); } }