question: public void casToTcfWriter ( InputStream aIs , JCas aJCas , OutputStream aOs ) throws WLFormatException { EnumSet < TextCorpusLayerTag > layersToRead = EnumSet . of ( TextCorpusLayerTag . TOKENS , TextCorpusLayerTag . SENTENCES ) ; List < TextCorpusLayerTag > layersToReplace = new ArrayList < TextCorpusLayerTag > ( ) ; if ( exists ( aJCas , POS . class ) || ! preserveIfEmpty ) { layersToReplace . add ( TextCorpusLayerTag . POSTAGS ) ; } if ( exists ( aJCas , Lemma . class ) || ! preserveIfEmpty ) { layersToReplace . add ( TextCorpusLayerTag . LEMMAS ) ; } if ( exists ( aJCas , NamedEntity . class ) || ! preserveIfEmpty ) { layersToReplace . add ( TextCorpusLayerTag . NAMED_ENTITIES ) ; } if ( exists ( aJCas , Dependency . class ) || ! preserveIfEmpty ) { layersToReplace . add ( TextCorpusLayerTag . PARSING_DEPENDENCY ) ; } if ( exists ( aJCas , CoreferenceChain . class ) || ! preserveIfEmpty ) { layersToReplace . add ( TextCorpusLayerTag . REFERENCES ) ; } TextCorpusStreamedWithReplaceableLayers textCorpus = null ; try { textCorpus = new TextCorpusStreamedWithReplaceableLayers ( aIs , layersToRead , EnumSet . copyOf ( layersToReplace ) , aOs ) ; write ( aJCas , textCorpus ) ; } finally { if ( textCorpus != null ) { try { textCorpus . close ( ) ; } catch ( IOException e ) { } } } }
target:  Merge annotations from CAS into an existing TCF file.