@Test public void readWithoutPath() { final ByteArrayInputStream input = new ByteArrayInputStream(("<slideshowfx><recentPresentations><recentPresentation><id>presentation01</id><openedDateTime>" + LocalDateTime.now() + "</openedDateTime></recentPresentation></recentPresentations></slideshowfx>").getBytes()); final Set<RecentPresentation> recentPresentations = readRecentPresentationFromStream(input); assertNotNull(recentPresentations); assertEquals(0, recentPresentations.size()); }
protected static Set<RecentPresentation> readRecentPresentationFromStream(final InputStream input) { final Set<RecentPresentation> presentations = new TreeSet<>(); try { final Document document = createDocumentFromInput(input); final Node recentPresentationsNode = getRecentPresentationsNode(document); if (recentPresentationsNode != null && recentPresentationsNode.hasChildNodes()) { final List<Node> recentPresentationNodes = getRecentPresentationNodes(recentPresentationsNode); presentations.addAll( recentPresentationNodes.stream() .map(ContextFileWorker::buildRecentPresentationFromNode) .filter(Objects::nonNull) .collect(Collectors.toList())); } } catch (ContextFileException e) { LOGGER.log(Level.SEVERE, "The context file can not be read", e); } return presentations; }
ContextFileWorker { protected static Set<RecentPresentation> readRecentPresentationFromStream(final InputStream input) { final Set<RecentPresentation> presentations = new TreeSet<>(); try { final Document document = createDocumentFromInput(input); final Node recentPresentationsNode = getRecentPresentationsNode(document); if (recentPresentationsNode != null && recentPresentationsNode.hasChildNodes()) { final List<Node> recentPresentationNodes = getRecentPresentationNodes(recentPresentationsNode); presentations.addAll( recentPresentationNodes.stream() .map(ContextFileWorker::buildRecentPresentationFromNode) .filter(Objects::nonNull) .collect(Collectors.toList())); } } catch (ContextFileException e) { LOGGER.log(Level.SEVERE, "The context file can not be read", e); } return presentations; } }
ContextFileWorker { protected static Set<RecentPresentation> readRecentPresentationFromStream(final InputStream input) { final Set<RecentPresentation> presentations = new TreeSet<>(); try { final Document document = createDocumentFromInput(input); final Node recentPresentationsNode = getRecentPresentationsNode(document); if (recentPresentationsNode != null && recentPresentationsNode.hasChildNodes()) { final List<Node> recentPresentationNodes = getRecentPresentationNodes(recentPresentationsNode); presentations.addAll( recentPresentationNodes.stream() .map(ContextFileWorker::buildRecentPresentationFromNode) .filter(Objects::nonNull) .collect(Collectors.toList())); } } catch (ContextFileException e) { LOGGER.log(Level.SEVERE, "The context file can not be read", e); } return presentations; } private  ContextFileWorker(); }
ContextFileWorker { protected static Set<RecentPresentation> readRecentPresentationFromStream(final InputStream input) { final Set<RecentPresentation> presentations = new TreeSet<>(); try { final Document document = createDocumentFromInput(input); final Node recentPresentationsNode = getRecentPresentationsNode(document); if (recentPresentationsNode != null && recentPresentationsNode.hasChildNodes()) { final List<Node> recentPresentationNodes = getRecentPresentationNodes(recentPresentationsNode); presentations.addAll( recentPresentationNodes.stream() .map(ContextFileWorker::buildRecentPresentationFromNode) .filter(Objects::nonNull) .collect(Collectors.toList())); } } catch (ContextFileException e) { LOGGER.log(Level.SEVERE, "The context file can not be read", e); } return presentations; } private  ContextFileWorker(); static Set<RecentPresentation> readRecentPresentationFromFile(final File contextFile); static void saveRecentPresentationToFile(final File contextFile, final RecentPresentation recentPresentation); static void updateRecentPresentationInFile(final File contextFile, final RecentPresentation recentPresentation); static boolean recentPresentationAlreadyPresent(final File contextFile, final RecentPresentation recentPresentation); static Set<RecentPresentation> purgeRecentPresentations(final InputStream input, final OutputStream output, final long numberOfRecentPresentationsToKeep); }
ContextFileWorker { protected static Set<RecentPresentation> readRecentPresentationFromStream(final InputStream input) { final Set<RecentPresentation> presentations = new TreeSet<>(); try { final Document document = createDocumentFromInput(input); final Node recentPresentationsNode = getRecentPresentationsNode(document); if (recentPresentationsNode != null && recentPresentationsNode.hasChildNodes()) { final List<Node> recentPresentationNodes = getRecentPresentationNodes(recentPresentationsNode); presentations.addAll( recentPresentationNodes.stream() .map(ContextFileWorker::buildRecentPresentationFromNode) .filter(Objects::nonNull) .collect(Collectors.toList())); } } catch (ContextFileException e) { LOGGER.log(Level.SEVERE, "The context file can not be read", e); } return presentations; } private  ContextFileWorker(); static Set<RecentPresentation> readRecentPresentationFromFile(final File contextFile); static void saveRecentPresentationToFile(final File contextFile, final RecentPresentation recentPresentation); static void updateRecentPresentationInFile(final File contextFile, final RecentPresentation recentPresentation); static boolean recentPresentationAlreadyPresent(final File contextFile, final RecentPresentation recentPresentation); static Set<RecentPresentation> purgeRecentPresentations(final InputStream input, final OutputStream output, final long numberOfRecentPresentationsToKeep);  }