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()); } } }
@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 <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; }
public void writeTo(final String location) throws IOException { try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(location)))) { writeTo(writer); } }
logger.info("Writing file " + outputFile); Files.createParentDirs(outputFile); try (Writer w = IO.utf8Writer(IO.buffer(IO.write(outputFile.getAbsolutePath())))) { w.write(naf);
try (final BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO.read(file .getAbsolutePath()))))) {
public void run() throws Throwable { final Writer writer = this.outputFile == null ? null : IO.utf8Writer(IO.buffer(IO .write(this.outputFile.getAbsolutePath())));
try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(file.getAbsolutePath())))) {
public static SubjectivityLexicon index(final String resourceFile) throws IOException { try (BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO .read(resourceFile))))) {
logger.info("Writing empty file " + outputFile); Files.createParentDirs(outputFile); try (Writer w = IO.utf8Writer(IO.buffer(IO.write(outputFile.getAbsolutePath())))) { w.write(document.toString());
try (BufferedReader reader = new BufferedReader(IO.utf8Reader(IO.buffer(IO.read(dataFile .getAbsolutePath()))))) { String line = reader.readLine();
try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(output.getAbsolutePath())))) { for (int childNum = 0; childNum < sortedIDs.size(); ++childNum) { final String childID = sortedIDs.get(childNum);