@Override protected void doProcess(JCas jCas) throws AnalysisEngineProcessException { DocumentAnnotation documentAnnotation = getDocumentAnnotation(jCas); String url = documentAnnotation.getSourceUri(); if (Strings.isNullOrEmpty(url)) { url = ConsumerUtils.getExternalId(documentAnnotation, false); } String extension = getExtension(); if (!Strings.isNullOrEmpty(extension)) { url = url + "." + extension; } File file = SourceUtils.urlToFile(basePath, url); try { getMonitor().debug("Writing {} to {}", url, file.getAbsolutePath()); writeToFile(jCas, file); } catch (Exception e) { getMonitor().warn("Failed to write file {}, deleting", file.getAbsolutePath(), e); if (!file.delete()) { getMonitor().warn("Failed to delete file {}", file.getAbsolutePath(), e); } } }