LeipzigDoccatSampleStream extends
    FilterObjectStream<String, DocumentSample> { public DocumentSample read() throws IOException { int count = 0; StringBuilder sampleText = new StringBuilder(); String line; while (count < sentencesPerDocument && (line = samples.read()) != null) { String tokens[] = SimpleTokenizer.INSTANCE.tokenize(line); if (tokens.length == 0) { throw new IOException("Empty lines are not allowed!"); } for (int i = 1; i < tokens.length; i++) { sampleText.append(tokens[i]); sampleText.append(' '); } count++; } if (sampleText.length() > 0) { return new DocumentSample(language, sampleText.toString()); } return null; } LeipzigDoccatSampleStream(String language, int sentencesPerDocument, 
      InputStream in); DocumentSample read();  }
@Test public void testParsingSample() throws IOException { InputStream in = LeipzigDoccatSampleStreamTest.class.getResourceAsStream( "/opennlp/tools/formats/leipzig-en.sample"); ObjectStream<DocumentSample> sampleStream = new LeipzigDoccatSampleStream("en", 2, in); DocumentSample doc1 = sampleStream.read(); assertEquals("en", doc1.getCategory()); DocumentSample doc2 = sampleStream.read(); assertEquals("en", doc2.getCategory()); DocumentSample doc3 = sampleStream.read(); assertEquals("en", doc3.getCategory()); DocumentSample doc4 = sampleStream.read(); assertEquals("en", doc4.getCategory()); assertNull(sampleStream.read()); }