public void writeTo(final String location) throws IOException { try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(location)))) { writeTo(writer); } }
public void run() throws Throwable { final Writer writer = this.outputFile == null ? null : IO.utf8Writer(IO.buffer(IO .write(this.outputFile.getAbsolutePath()))); IO.closeQuietly(writer);
public static <T extends Lexeme, L extends Lexicon<T>> L readFrom(final Class<L> lexiconClass, final Class<T> lexemeClass, final String location) throws IOException { // Try to open a file at the location specified, falling back to search on the classpath Reader reader = null; try { reader = IO.utf8Reader(IO.buffer(IO.read(location))); } catch (final Throwable ex) { final URL url = lexiconClass.getResource(location); if (url == null) { Throwables.propagateIfPossible(ex, IOException.class); Throwables.propagate(ex); } reader = IO.utf8Reader(url.openStream()); } // Read the lexicon from the opened reader try { return readFrom(lexiconClass, lexemeClass, reader); } finally { reader.close(); } }
public static KAFDocument readDocument(@Nullable final Path path) throws IOException { final KAFDocument document; if (path == null) { document = KAFDocument.createFromStream(IO.utf8Reader(IO.buffer(System.in))); document.getPublic().publicId = ""; } else { try (BufferedReader reader = Files.newBufferedReader(path)) { document = KAFDocument.createFromStream(reader); document.getPublic().publicId = path.toString(); } } return document; }
final Model model = this.generator.generate(document, null); Files.createParentDirs(outputFile); try (Writer writer = IO.utf8Writer(IO.write(outputFile.getAbsolutePath()))) { renderer.renderAll(writer, document, model, this.template, null);
private static void writeBinary(final Stream<Record> records, final File file) throws IOException { final String base = file.getAbsolutePath(); final Dictionary<URI> dictionary = Dictionary.createLocalDictionary(URI.class, new File( base + ".dict")); final Serializer serializer = new Serializer(false, dictionary, Statements.VALUE_FACTORY); final CountingOutputStream stream = new CountingOutputStream(IO.write(base + ".gz")); try { records.toHandler(new Handler<Record>() { private int records = 0; @Override public void handle(final Record record) throws Throwable { if (record == null || this.records > 0 && this.records % 1000 == 0) { LOGGER.info("{} records, {} bytes processed ({} bytes/record)", this.records, stream.getCount(), stream.getCount() / this.records); } if (record != null) { serializer.toStream(stream, record); ++this.records; } } }); } finally { IO.closeQuietly(records); IO.closeQuietly(stream); } }
try (InputStream stream = IO.read(file.toString())) { byte[] bytes; bytes = ByteStreams.toByteArray(stream); document = KAFDocument.createFromStream(IO.utf8Reader(new ByteArrayInputStream( bytes))); } catch (final Throwable ex) {
final OutputStream stream = IO.write(file.getAbsolutePath());
IO.closeQuietly(tsvWriter); IO.closeQuietly(htmlWriter);
try (InputStream configStream = IO.read(configFile.getAbsolutePath())) { config.load(configStream);
String location = Environment.getProperty("rdfpro.rules." + rulesetName); location = location != null ? location : rulesetName; rulesetURLs.add(IO.extractURL(location).toString());
@Override public void reduce(final Value key, final Statement[] stmts, final RDFHandler handler) throws RDFHandlerException { final RDFHandler session = RuleProcessor.this.engine.newSession(RDFHandlers .ignoreMethods(handler, RDFHandlers.METHOD_START_RDF | RDFHandlers.METHOD_END_RDF | RDFHandlers.METHOD_CLOSE)); try { session.startRDF(); for (final Statement stmt : stmts) { session.handleStatement(stmt); } session.endRDF(); } finally { IO.closeQuietly(session); } }
try (InputStream configStream = IO.read(configFile.getAbsolutePath())) { config.load(configStream);
public static void writeDocument(final KAFDocument document, @Nullable final Path location) throws IOException { if (location == null) { System.out.write(document.toString().getBytes(Charsets.UTF_8)); } else { try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(location.toString())))) { writer.write(document.toString()); } } }
try (final BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO.read(file .getAbsolutePath()))))) {
@SuppressWarnings("unchecked") @Override public void handle(final BindingSet bindings) throws Throwable { if (this.writer == null) { this.writer = IO.utf8Writer(IO.buffer(IO.write(Query.this.file .getAbsolutePath()))); writerToClose.set(this.writer); this.variables = stream.getProperty("variables", List.class); for (int i = 0; i < this.variables.size(); ++i) { this.writer.write(i > 0 ? "\t?" : "?"); this.writer.write(this.variables.get(i)); } this.writer.write("\n"); } if (bindings != null) { this.writer.write(TestUtil.encode(this.variables, bindings)); this.writer.write("\n"); tracker.increment(); } }
public static SubjectivityLexicon index(final String resourceFile) throws IOException { try (BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO .read(resourceFile))))) {
try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(file.getAbsolutePath())))) {
try (BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO.read(dataFile .getAbsolutePath()))))) { String line = reader.readLine();
logger.info("Writing file " + outputFile); Files.createParentDirs(outputFile); try (Writer w = IO.utf8Writer(IO.buffer(IO.write(outputFile.getAbsolutePath())))) { w.write(naf);