@Test public void testEmpty() throws Exception { instance.exportToWorkspace(EXPORT_FILE, true); ArgumentCaptor<File> fileArgumentCaptor = ArgumentCaptor.forClass(File.class); verify(handler).transferFileToWorkspace(eq(EXPORT_FILE), fileArgumentCaptor.capture(), eq(true), eq(false)); assertThat(fileArgumentCaptor.getValue().length()).isEqualTo(0); }
public void exportToWorkspace(String filename, boolean ascending) throws IOException, ProcessingException { for (JsonLineWriter value : this.writersByLevel.values()) { value.close(); } File combinedSortedJsonLineFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); try { try (OutputStream outputStream = new FileOutputStream(combinedSortedJsonLineFile); JsonLineWriter writer = new JsonLineWriter(outputStream)) { List<Integer> levels = this.filesByLevel.keySet().stream() .sorted(ascending ? Comparator.naturalOrder() : Comparator.reverseOrder()) .collect(Collectors.toList()); for (Integer level : levels) { File fileLevel = this.filesByLevel.get(level); try (InputStream is = new FileInputStream(fileLevel); JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>( is, TYPE_REFERENCE)) { while (lineGenericIterator.hasNext()) { writer.addEntry(lineGenericIterator.next()); } } } } handler.transferFileToWorkspace(filename, combinedSortedJsonLineFile, true, false); } finally { for (File file : filesByLevel.values()) { FileUtils.deleteQuietly(file); } } }
SortedLevelJsonLineWriter implements AutoCloseable { public void exportToWorkspace(String filename, boolean ascending) throws IOException, ProcessingException { for (JsonLineWriter value : this.writersByLevel.values()) { value.close(); } File combinedSortedJsonLineFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); try { try (OutputStream outputStream = new FileOutputStream(combinedSortedJsonLineFile); JsonLineWriter writer = new JsonLineWriter(outputStream)) { List<Integer> levels = this.filesByLevel.keySet().stream() .sorted(ascending ? Comparator.naturalOrder() : Comparator.reverseOrder()) .collect(Collectors.toList()); for (Integer level : levels) { File fileLevel = this.filesByLevel.get(level); try (InputStream is = new FileInputStream(fileLevel); JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>( is, TYPE_REFERENCE)) { while (lineGenericIterator.hasNext()) { writer.addEntry(lineGenericIterator.next()); } } } } handler.transferFileToWorkspace(filename, combinedSortedJsonLineFile, true, false); } finally { for (File file : filesByLevel.values()) { FileUtils.deleteQuietly(file); } } } }
SortedLevelJsonLineWriter implements AutoCloseable { public void exportToWorkspace(String filename, boolean ascending) throws IOException, ProcessingException { for (JsonLineWriter value : this.writersByLevel.values()) { value.close(); } File combinedSortedJsonLineFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); try { try (OutputStream outputStream = new FileOutputStream(combinedSortedJsonLineFile); JsonLineWriter writer = new JsonLineWriter(outputStream)) { List<Integer> levels = this.filesByLevel.keySet().stream() .sorted(ascending ? Comparator.naturalOrder() : Comparator.reverseOrder()) .collect(Collectors.toList()); for (Integer level : levels) { File fileLevel = this.filesByLevel.get(level); try (InputStream is = new FileInputStream(fileLevel); JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>( is, TYPE_REFERENCE)) { while (lineGenericIterator.hasNext()) { writer.addEntry(lineGenericIterator.next()); } } } } handler.transferFileToWorkspace(filename, combinedSortedJsonLineFile, true, false); } finally { for (File file : filesByLevel.values()) { FileUtils.deleteQuietly(file); } } } SortedLevelJsonLineWriter(HandlerIO handler); }
SortedLevelJsonLineWriter implements AutoCloseable { public void exportToWorkspace(String filename, boolean ascending) throws IOException, ProcessingException { for (JsonLineWriter value : this.writersByLevel.values()) { value.close(); } File combinedSortedJsonLineFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); try { try (OutputStream outputStream = new FileOutputStream(combinedSortedJsonLineFile); JsonLineWriter writer = new JsonLineWriter(outputStream)) { List<Integer> levels = this.filesByLevel.keySet().stream() .sorted(ascending ? Comparator.naturalOrder() : Comparator.reverseOrder()) .collect(Collectors.toList()); for (Integer level : levels) { File fileLevel = this.filesByLevel.get(level); try (InputStream is = new FileInputStream(fileLevel); JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>( is, TYPE_REFERENCE)) { while (lineGenericIterator.hasNext()) { writer.addEntry(lineGenericIterator.next()); } } } } handler.transferFileToWorkspace(filename, combinedSortedJsonLineFile, true, false); } finally { for (File file : filesByLevel.values()) { FileUtils.deleteQuietly(file); } } } SortedLevelJsonLineWriter(HandlerIO handler); void addEntry(JsonLineModel line); void exportToWorkspace(String filename, boolean ascending); @Override void close(); }
SortedLevelJsonLineWriter implements AutoCloseable { public void exportToWorkspace(String filename, boolean ascending) throws IOException, ProcessingException { for (JsonLineWriter value : this.writersByLevel.values()) { value.close(); } File combinedSortedJsonLineFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); try { try (OutputStream outputStream = new FileOutputStream(combinedSortedJsonLineFile); JsonLineWriter writer = new JsonLineWriter(outputStream)) { List<Integer> levels = this.filesByLevel.keySet().stream() .sorted(ascending ? Comparator.naturalOrder() : Comparator.reverseOrder()) .collect(Collectors.toList()); for (Integer level : levels) { File fileLevel = this.filesByLevel.get(level); try (InputStream is = new FileInputStream(fileLevel); JsonLineGenericIterator<JsonLineModel> lineGenericIterator = new JsonLineGenericIterator<>( is, TYPE_REFERENCE)) { while (lineGenericIterator.hasNext()) { writer.addEntry(lineGenericIterator.next()); } } } } handler.transferFileToWorkspace(filename, combinedSortedJsonLineFile, true, false); } finally { for (File file : filesByLevel.values()) { FileUtils.deleteQuietly(file); } } } SortedLevelJsonLineWriter(HandlerIO handler); void addEntry(JsonLineModel line); void exportToWorkspace(String filename, boolean ascending); @Override void close();  }