private void swapLocalFilePrefixes(String to, String from) { Consumer<Node> fileFinder = n -> n.localFiles().forEach(f -> { try { f.setAccessible(true); String fPath = (String) f.get(n); if (fPath == null) { return; } if (fPath.startsWith(to)) { log.info("File " + f.getName() + " was already in correct format " + fPath); return; } if (!fPath.startsWith(from)) { throw new HalException(FATAL, "Local file: " + fPath + " has incorrect prefix - must match " + from); } fPath = to + fPath.substring(from.length()); f.set(n, fPath); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e); } finally { f.setAccessible(false); } }); recursiveConsume(fileFinder); }
private void swapLocalFilePrefixes(String to, String from) { Consumer<Node> fileFinder = n -> n.localFiles().forEach(f -> { try { f.setAccessible(true); String fPath = (String) f.get(n); if (fPath == null) { return; } if (fPath.startsWith(to)) { log.info("File " + f.getName() + " was already in correct format " + fPath); return; } if (!fPath.startsWith(from)) { throw new HalException(FATAL, "Local file: " + fPath + " has incorrect prefix - must match " + from); } fPath = to + fPath.substring(from.length()); f.set(n, fPath); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e); } finally { f.setAccessible(false); } }); recursiveConsume(fileFinder); }
public void recursiveConsume(Consumer<Node> consumer) { consumer.accept(this); NodeIterator children = getChildren(); Node child = children.getNext(); while (child != null) { child.recursiveConsume(consumer); child = children.getNext(); } }
public void recursiveConsume(Consumer<Node> consumer) { consumer.accept(this); NodeIterator children = getChildren(); Node child = children.getNext(); while (child != null) { child.recursiveConsume(consumer); child = children.getNext(); } }
recursiveConsume(fileFinder);