JCasFileWriter_ImplBase extends JCasConsumer_ImplBase { @Override public void collectionProcessComplete() throws AnalysisEngineProcessException { if (zipOutputStream != null) { closeQuietly(zipOutputStream); } if (singularTargetStream != null) { closeQuietly(singularTargetStream); } super.collectionProcessComplete(); }  @Override void collectionProcessComplete(); static final String PARAM_TARGET_LOCATION; static final String PARAM_SINGULAR_TARGET; static final String PARAM_COMPRESSION; static final String PARAM_STRIP_EXTENSION; static final String PARAM_USE_DOCUMENT_ID; static final String PARAM_ESCAPE_FILENAME; static final String PARAM_OVERWRITE; }
@Test public void writeToZip() throws Exception { AnalysisEngine ae = createEngine(DummyWriter.class, DummyWriter.PARAM_TARGET_LOCATION, "jar:file:target/out.zip", DummyWriter.PARAM_OVERWRITE, true); JCas jcas = JCasFactory.createJCas(); ae.process(jcas); ae.process(jcas); ae.process(jcas); ae.collectionProcessComplete(); assertEquals(asList("file-0.txt", "file-1.txt", "file-2.txt"), listContents("target/out.zip")); }
@Test public void writeToZip2() throws Exception { AnalysisEngine ae = createEngine(DummyWriter.class, DummyWriter.PARAM_TARGET_LOCATION, "jar:file:target/out2.zip!test", DummyWriter.PARAM_OVERWRITE, true); JCas jcas = JCasFactory.createJCas(); ae.process(jcas); ae.process(jcas); ae.process(jcas); ae.collectionProcessComplete(); assertEquals(asList("test/file-0.txt", "test/file-1.txt", "test/file-2.txt"), listContents("target/out2.zip")); }
@Test public void writeToSingularTarget() throws Exception { File target = new File("target/test-output/singular.txt"); AnalysisEngine ae = createEngine(DummyWriter.class, DummyWriter.PARAM_TARGET_LOCATION, target, DummyWriter.PARAM_SINGULAR_TARGET, true, DummyWriter.PARAM_OVERWRITE, true); JCas jcas = JCasFactory.createJCas(); ae.process(jcas); ae.process(jcas); ae.process(jcas); ae.collectionProcessComplete(); String expected = "This is the file 0\n" + "This is the file 1\n" + "This is the file 2\n"; assertEquals(expected, FileUtils.readFileToString(target, "UTF-8")); }