TsvStreamer implements AutoCloseable, Supplier<Stream<String[]>> { @Override public Stream<String[]> get() { return new BufferedReader(this.reader).lines() .map(TsvStreamer::splitByTabsAndTrimWrappingQuotes) .filter(lineFields -> !lineFields[0].startsWith("#")); } TsvStreamer(Reader reader); @Override Stream<String[]> get(); @Override void close(); static TsvStreamer empty();  }
@Test public void commentLinesAreFiltered() { subject = new TsvStreamer(new InputStreamReader(new ByteArrayInputStream(DATA.getBytes()))); assertThat(subject.get().collect(Collectors.toList())) .hasSize(DATA.split("\n").length - 1) .containsExactly(HEADER_LINE_AS_ARRAY, VALUES_LINE_AS_ARRAY); }
@Test public void wrappingQuotesAreTrimmed() { subject = new TsvStreamer(new InputStreamReader(new ByteArrayInputStream(DATA_WITH_QUOTES.getBytes()))); assertThat(subject.get().collect(Collectors.toList())) .hasSize(DATA_WITH_QUOTES.split("\n").length - 1) .containsExactly(HEADER_LINE_AS_ARRAY, VALUES_LINE_AS_ARRAY, VALUES_LINE_WITH_IN_QUOTES_ONLY); }
@Test public void streamIsExhaustedAfterReading() { subject = new TsvStreamer(new InputStreamReader(new ByteArrayInputStream(DATA.getBytes()))); assertThat(subject.get().collect(Collectors.toList())) .hasSize(2) .containsExactly(HEADER_LINE_AS_ARRAY, VALUES_LINE_AS_ARRAY); assertThat(subject.get().collect(Collectors.toList())).isEmpty(); }