private String writeFile(String data) throws IOException { File file = File.createTempFile("lombok-processor-report-", ".txt"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file)); writer.write(data); writer.close(); return "Report written to '" + file.getCanonicalPath() + "'\n"; }
public void handleTokenize(String arg, OutputStream outStream) throws IOException { if (arg == null) { return; } List<? extends HasWord> tokens = parser.tokenize(arg); OutputStreamWriter osw = new OutputStreamWriter(outStream, "utf-8"); for (int i = 0; i < tokens.size(); ++i) { HasWord word = tokens.get(i); if (i > 0) { osw.write(" "); } osw.write(word.toString()); } osw.write("\n"); osw.flush(); }
/** * Saves the content of the string buffer to the specified file. * * @param file the file to write to. * @param content the content to write to the file. */ protected void saveSuiteContent(final File file, final XMLStringBuffer content) { try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { fw.write(content.getStringBuffer().toString()); } catch (IOException ioe) { // TODO CQ is this normal to swallow exception here LOGGER.error("IO Exception", ioe); } } }
return false; OutputStreamWriter osw = new OutputStreamWriter(IOUtil.newOutputStream(textmodel), "UTF-8"); osw.write("version: " + Encoder.MODEL_VERSION + "\n"); osw.write("cost-factor: " + costFactor_ + "\n"); osw.write("maxid: " + maxid_ + "\n"); osw.write("xsize: " + xsize_ + "\n"); osw.write("\n"); for (String y : y_) osw.write(y + "\n"); osw.write("\n"); for (String utempl : unigramTempls_) osw.write(utempl + "\n"); osw.write(bitempl + "\n"); osw.write("\n"); osw.write(pair.getValue() + " " + pair.getKey() + "\n"); osw.write("\n"); osw.write(val + "\n");
@Test public void testSimpleFileWriteAndRead() throws Exception { final String testLine = "Hello Upload!"; final Path path = new Path(basePath, "test.txt"); try { try (FSDataOutputStream out = fs.create(path, FileSystem.WriteMode.OVERWRITE); OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { writer.write(testLine); } // just in case, wait for the path to exist checkPathExistence(path, true, deadline); try (FSDataInputStream in = fs.open(path); InputStreamReader ir = new InputStreamReader(in, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(ir)) { String line = reader.readLine(); assertEquals(testLine, line); } } finally { fs.delete(path, false); } checkPathExistence(path, false, deadline); }
public static void writeFile(String filePathAndName, String fileContent) { try { OutputStream outstream = new FileOutputStream(filePathAndName); OutputStreamWriter out = new OutputStreamWriter(outstream); out.write(fileContent); out.close(); } catch (java.io.IOException e) { e.printStackTrace(); } }
/** * Saves the content of the string buffer to the specified file. * * @param file the file to write to. * @param content the content to write to the file. */ protected void saveSuiteContent(final File file, final XMLStringBuffer content) { try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { fw.write(content.getStringBuffer().toString()); } catch (IOException ioe) { // TODO CQ is this normal to swallow exception here LOGGER.error("IO Exception", ioe); } } }
private boolean sendCommand(String cmd, @NotNull Process pythonProcess) { try { OutputStreamWriter writer = new OutputStreamWriter(pythonProcess.getOutputStream()); writer.write(cmd); writer.write("\n"); writer.flush(); return true; } catch (Exception e) { _.msg("\nFailed to send command to interpreter: " + cmd); return false; } }
OutputStreamWriter osw = new OutputStreamWriter(IOUtil.newOutputStream(filename + ".txt"), "UTF-8"); osw.write("version: " + Encoder.MODEL_VERSION + "\n"); osw.write("cost-factor: " + costFactor_ + "\n"); osw.write("maxid: " + maxid_ + "\n"); osw.write("xsize: " + xsize_ + "\n"); osw.write("\n"); for (String y : y_) osw.write(y + "\n"); osw.write("\n"); for (String utempl : unigramTempls_) osw.write(utempl + "\n"); osw.write(bitempl + "\n"); osw.write("\n"); for (MutableDoubleArrayTrieInteger.KeyValuePair pair : dic_) osw.write(pair.getValue() + " " + pair.getKey() + "\n"); osw.write("\n"); osw.write(val + "\n"); osw.close();
public static void processLabeledData(String input,String enc1, String enc2) throws Exception{ FileInputStream is = new FileInputStream(input); // is.skip(3); //skip BOM BufferedReader r = new BufferedReader( new InputStreamReader(is, enc1)); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(input+"."+enc2), enc2); while(true) { String sent = r.readLine(); if(null == sent) break; w.write(sent); w.write('\n'); } r.close(); w.close(); }
private static Path createTempFilePath(String contents) throws IOException { File tempFile = File.createTempFile("test_contents", "tmp"); tempFile.deleteOnExit(); try (OutputStreamWriter wrt = new OutputStreamWriter(new FileOutputStream(tempFile))) { wrt.write(contents); } return new Path(tempFile.toURI().toString()); } }
public void handleLemma(String arg, OutputStream outStream) throws IOException { if (arg == null) { return; } List<CoreLabel> tokens = parser.lemmatize(arg); OutputStreamWriter osw = new OutputStreamWriter(outStream, "utf-8"); for (int i = 0; i < tokens.size(); ++i) { CoreLabel word = tokens.get(i); if (i > 0) { osw.write(" "); } osw.write(word.lemma()); } osw.write("\n"); osw.flush(); }
public void saveToFile(ArrayList<ToDoItem> items) throws JSONException, IOException { FileOutputStream fileOutputStream; OutputStreamWriter outputStreamWriter; fileOutputStream = mContext.openFileOutput(mFileName, Context.MODE_PRIVATE); outputStreamWriter = new OutputStreamWriter(fileOutputStream); outputStreamWriter.write(toJSONArray(items).toString()); outputStreamWriter.close(); fileOutputStream.close(); }
public static void writeStringToFile(@NonNull File file, @NonNull String content) throws IOException { final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), ACRAConstants.UTF8); try { writer.write(content); writer.flush(); } finally { safeClose(writer); } }
/** * Write manifest using JAXP transformer */ private void writeManifest( File manifestFile, Document doc ) throws IOException, TransformerException { TransformerFactory xfactory = TransformerFactory.newInstance(); Transformer xformer = xfactory.newTransformer(); xformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" ); Source source = new DOMSource( doc ); OutputStreamWriter writer = null; try { manifestFile.getParentFile().mkdirs(); String encoding = doc.getXmlEncoding() != null ? doc.getXmlEncoding() : "UTF-8"; writer = new OutputStreamWriter( new FileOutputStream( manifestFile, false ), encoding ); if ( doc.getXmlEncoding() != null && doc.getXmlVersion() != null ) { String xmldecl = String .format( "<?xml version=\"%s\" encoding=\"%s\"?>%n", doc.getXmlVersion(), doc.getXmlEncoding() ); writer.write( xmldecl ); } Result result = new StreamResult( writer ); xformer.transform( source, result ); } finally { IOUtils.closeQuietly( writer ); } }
private void writeToFile(String data, String file) throws IOException { Path resFile = new Path(file); FileSystem fs = resFile.getFileSystem(conf); FSDataOutputStream out = fs.create(resFile); try { if (data != null && !data.isEmpty()) { OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); writer.write(data); writer.write((char) terminator); writer.flush(); } } finally { IOUtils.closeStream(out); } }