public static PrintWriter openPrintWriter(File file) throws IOException { return openPrintWriter(file, "utf-8", false); }
public static Properties readProperties(File inFile) throws IOException { return readProperties(inFile, "utf-8"); }
public static BufferedWriter openBufferedWriter(File file) throws IOException { return openBufferedWriter(file, "utf-8", false); }
public static BufferedReader openReader(File file) throws IOException { return openReader(file, "utf-8"); }
@Override protected OutputStream getOutputStream(DocumentMetadata meta) throws IOException { Path outRelativePath = outPathFunc.apply(meta); Path resultPath = outBasePath.resolve(outRelativePath); resultPath = IoUtils.addExtension(resultPath, XMI_FILE_EXTENSION); // does not create missing parents // return Files.newOutputStream(resultPath); return FileUtils.openOutputStream(resultPath.toFile()); } }
public static Properties readProperties(File inFile, String encoding) throws IOException { Properties props = new Properties(); BufferedReader r = openReader(inFile, encoding); try { props.load(r); } finally { closeQuietly(r); } return props; }
public static PrintWriter openPrintWriter(File file, boolean append) throws IOException { return openPrintWriter(file, "utf-8", append); }
public static Properties parseConfig(File modelDir) throws IOException { File feCfgFile = new File(modelDir, FILENAME_FEATURE_EXTRACTION_CONFIG); return IoUtils.readProperties(feCfgFile); }
public static PrintWriter openPrintWriter(File file, String encoding, boolean append) throws IOException { return new PrintWriter(openBufferedWriter(file, encoding, append)); }
public static void read(File file, CAS cas) throws IOException, SAXException { BufferedReader in = IoUtils.openReader(file); try { read(in, cas); } finally { IOUtils.closeQuietly(in); } }
@Override public void process(CAS cas) throws AnalysisEngineProcessException { String docURIStr = getDocumentUri(cas); if (docURIStr == null) { throw new UnsupportedOperationException("Document URI is not specified in a CAS"); } // phase 0 - open output stream try { docURI = new URI(docURIStr); } catch (URISyntaxException e) { throw new AnalysisEngineProcessException(e); } String outFileName = new File(docURI).getName() + OUTPUT_FILE_EXTENSION; File outFile = new File(outputDir, outFileName); PrintWriter out; try { out = IoUtils.openPrintWriter(outFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } try { process(cas, out); } finally { IOUtils.closeQuietly(out); } }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) return false; // dataWriterFactoryClass = InitializableFactory.getClass(dataWriteFactoryClassName, SequenceDataWriterFactory.class); // if (outputBaseDir.exists() && !outputBaseDir.isDirectory()) { throw new IllegalStateException(format("%s exists but it is not a directory", outputBaseDir)); } File feCfgFile = new File(outputBaseDir, TieredFeatureExtractors.FILENAME_FEATURE_EXTRACTION_CONFIG); try { featureExtractionCfg = IoUtils.readProperties(feCfgFile); } catch (IOException e) { throw new ResourceInitializationException(e); } initialize(); return true; }
public static void writeProperties(Properties props, File outFile) throws IOException { BufferedWriter ow = openBufferedWriter(outFile); try { props.store(ow, null); } finally { closeQuietly(ow); } }
out = IoUtils.openPrintWriter(outFile);
public static void write(Properties props, File outFile) throws IOException { BufferedWriter bw = openBufferedWriter(outFile); try { props.store(bw, null); } finally { closeQuietly(bw); } }