@Override protected void convertCorpus(Sentence sentence, BufferedWriter bw) throws IOException { List<String[]> collector = Utility.convertSentenceToNER(sentence, tagSet); for (String[] tuple : collector) { bw.write(tuple[0]); bw.write('\t'); bw.write(tuple[1]); bw.write('\t'); bw.write(tuple[2]); bw.newLine(); } }
public static void print(String[][] cols) throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename)); for (String[] col : cols) { if (col.length >= 2) { out.write(col[0] + "\t" + col[1] + "\n"); } else { out.write("\n"); } } out.flush(); out.close(); }
public static void main(String[] args) throws Exception { System.out.println(Arrays.asList(args)); File thisFolder = new File(SelfrunTest.class.getResource("/org/embulk/cli/DummyMain.class").toURI()).getParentFile(); try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(thisFolder, "args.txt")), Charset.defaultCharset()))) { for (String arg : args) { writer.write(arg); writer.newLine(); } } } }
public static void writeFile(String string, File f) throws IOException { f.getParentFile().mkdirs(); try (FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw)) { bw.write(string); } }
/** * @throws Exception If failed. */ private void beforeJob() throws Exception { IgniteFileSystem igfs = grid(0).fileSystem(HadoopAbstractSelfTest.igfsName); igfs.clear(); igfs.mkdirs(new IgfsPath(PATH_INPUT)); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create( new IgfsPath(PATH_INPUT + "/test.file"), true)))) { bw.write("word"); } }
private Path writeTextTo(final String location) throws IOException { final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); buffy.newLine(); buffy.flush(); } return path; } }
public static void writeToFile(File file, Set<String> content) throws IOException { FileWriter fw = new FileWriter(file, false); BufferedWriter bw = new BufferedWriter(fw); Iterator<String> iter = content.iterator(); while (iter.hasNext()) { bw.write(iter.next()); bw.write(System.lineSeparator()); } bw.close(); }
/** * Creates a temporary file that contains the given string. * The file is written with the platform's default encoding. * * <p>The temp file is automatically deleted on JVM exit. * * @param contents The contents to be written to the file. * @return The temp file URI. */ public static String createTempFile(String contents) throws IOException { File f = File.createTempFile("flink_test_", ".tmp"); f.deleteOnExit(); try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) { out.write(contents); } return f.toURI().toString(); }
private static void writePoint(double[] coordinates, StringBuilder buffer, BufferedWriter out) throws IOException { buffer.setLength(0); // write coordinates for (int j = 0; j < coordinates.length; j++) { buffer.append(FORMAT.format(coordinates[j])); if (j < coordinates.length - 1) { buffer.append(DELIMITER); } } out.write(buffer.toString()); out.newLine(); }
private Path writeTextTo(final String location) throws IOException { final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); buffy.newLine(); buffy.flush(); } return path; }
public void testNewWriter() throws IOException { File temp = createTempFile(); try { Files.newWriter(temp, null); fail("expected exception"); } catch (NullPointerException expected) { } try { Files.newWriter(null, Charsets.UTF_8); fail("expected exception"); } catch (NullPointerException expected) { } BufferedWriter w = Files.newWriter(temp, Charsets.UTF_8); try { w.write(I18N); } finally { w.close(); } File i18nFile = getTestFile("i18n.txt"); assertTrue(Files.equal(i18nFile, temp)); }
private static boolean writeValue(Socket client, String value) { boolean result; BufferedWriter out = null; try { OutputStream clientStream = client.getOutputStream(); out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); out.write(value); out.write("\n"); out.flush(); result = true; } catch (Exception e) { result = false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { result = false; } } } return result; }
@Override public void saveToFilename(String file) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) { for (int i = 0, sz = size(); i < sz; i++) { bw.write(i + "=" + get(i) + '\n'); } } catch (IOException e) { throw new RuntimeIOException(e); } // give up }
private static void writePoint(double[] data, StringBuilder buffer, BufferedWriter out) throws IOException { buffer.setLength(0); // write coordinates for (int j = 0; j < data.length; j++) { buffer.append(FORMAT.format(data[j])); if (j < data.length - 1) { buffer.append(DELIMITER); } } out.write(buffer.toString()); out.newLine(); } }
private Path writeTextTo(final String location) throws IOException { final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); buffy.newLine(); buffy.flush(); } return path; } }
@Override public void execute(Tuple input) { Values values = (Values) input.getValue(0); byte[] array = serializer.write(values, null).array(); String data = new String(array); try { writer.write(data + "\n"); writer.flush(); collector.ack(input); } catch (IOException e) { LOG.error("Error while writing data to socket.", e); collector.reportError(e); collector.fail(input); } }
static void writeFile(File outputFile, String str) throws IOException { BufferedWriter w = new BufferedWriter(new FileWriter(outputFile)); w.write(str); w.close(); }