Source:
private void registerFiles(Map<String, Map<URI, String>> digestsMap) { long start = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); final int[] cntArray = { 0 }; digestsMap.entrySet().forEach(digestGroup -> { Map<URI, String> digestToPath = digestGroup.getValue(); if (digestToPath.size() == 0) { return; } sb.append(digestGroup.getKey()).append(":\n"); digestToPath.entrySet().forEach(manifestEntry -> { sb.append(manifestEntry.getValue()) .append(' ') .append(Paths.get(manifestEntry.getKey()).toString()) .append('\n'); cntArray[0]++; }); }); int entryCount = cntArray[0]; if (sb.length() == entryCount) { return; } try { String longleafCommmand = longleafBaseCommand + " register --force -m @-"; log.info("Registering with longleaf: {}", longleafCommmand); Process process = Runtime.getRuntime().exec(longleafCommmand); try (OutputStream pipeOut = process.getOutputStream()) { pipeOut.write(sb.toString().getBytes(UTF_8)); } int exitVal = process.waitFor(); String line; try (BufferedReader in = new BufferedReader( new InputStreamReader(process.getInputStream()))) { while ((line = in.readLine()) != null) { longleafLog.info(line); } } try (BufferedReader err = new BufferedReader( new InputStreamReader(process.getErrorStream()))) { while ((line = err.readLine()) != null) { longleafLog.error(line); } } if (exitVal == 0) { log.info("Successfully registered entries to longleaf", entryCount); } else { throw new ServiceException("Failed to register " + entryCount + " entries to Longleaf. " + "Check longleaf logs, command returned: " + exitVal); } } catch (IOException e) { log.error("IOException while trying to register batch of entries to longleaf", entryCount, e); } catch (InterruptedException e) { log.error("InterruptedException while trying to register entries to longleaf", entryCount, e); } log.info("Longleaf registration completed in: ms", (System.currentTimeMillis() - start)); }

Target:
private void registerFiles(Map<String, Map<URI, String>> digestsMap) { long start = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); MutableInt cnt = new MutableInt(0); digestsMap.entrySet().forEach(digestGroup -> { Map<URI, String> digestToPath = digestGroup.getValue(); if (digestToPath.size() == 0) { return; } sb.append(digestGroup.getKey()).append(":\n"); digestToPath.entrySet().forEach(manifestEntry -> { sb.append(manifestEntry.getValue()) .append(' ') .append(Paths.get(manifestEntry.getKey()).toString()) .append('\n'); cnt.increment(); }); }); int entryCount = cnt.getValue(); if (sb.length() == entryCount) { return; } try { String longleafCommmand = longleafBaseCommand + " register --force -m @-"; log.info("Registering with longleaf: {}", longleafCommmand); Process process = Runtime.getRuntime().exec(longleafCommmand); try (OutputStream pipeOut = process.getOutputStream()) { pipeOut.write(sb.toString().getBytes(UTF_8)); } int exitVal = process.waitFor(); String line; try (BufferedReader in = new BufferedReader( new InputStreamReader(process.getInputStream()))) { while ((line = in.readLine()) != null) { longleafLog.info(line); } } try (BufferedReader err = new BufferedReader( new InputStreamReader(process.getErrorStream()))) { while ((line = err.readLine()) != null) { longleafLog.error(line); } } if (exitVal == 0) { log.info("Successfully registered entries to longleaf", entryCount); } else { throw new ServiceException("Failed to register " + entryCount + " entries to Longleaf. " + "Check longleaf logs, command returned: " + exitVal); } } catch (IOException e) { log.error("IOException while trying to register batch of entries to longleaf", entryCount, e); } catch (InterruptedException e) { log.error("InterruptedException while trying to register entries to longleaf", entryCount, e); } log.info("Longleaf registration completed in: ms", (System.currentTimeMillis() - start)); }