List of usage examples for java.io OutputStreamWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:com.yhfudev.SimulatorForSelfStabilizing.java
private static void saveGraph(Graph g, OutputStreamWriter fwr) throws IOException { fwr.append("DGS004\nnull 0 0\n"); for (Node node : g.getNodeSet()) { fwr.append("an \"" + node.getId() + "\"\n"); }/*from ww w . j av a 2 s . com*/ for (Edge edge : g.getEdgeSet()) { Node n1; Node n2; n1 = edge.getNode0(); n2 = edge.getNode1(); fwr.append("ae \"" + edge.getId() + "\" \"" + n1.getId() + "\" \"" + n2.getId() + "\"\n"); } }
From source file:org.apache.commons.net.examples.mail.POP3ExportMbox.java
private static void writeMbox(POP3Client pop3, OutputStreamWriter fw, int i) throws IOException { final SimpleDateFormat DATE_FORMAT // for mbox From_ lines = new SimpleDateFormat("EEE MMM dd HH:mm:ss YYYY"); String replyTo = "MAILER-DAEMON"; // default Date received = new Date(); BufferedReader r = (BufferedReader) pop3.retrieveMessage(i); fw.append("From "); fw.append(replyTo);/*w w w.j a v a2 s .co m*/ fw.append(' '); fw.append(DATE_FORMAT.format(received)); fw.append("\n"); String line; while ((line = r.readLine()) != null) { if (startsWith(line, PATFROM)) { fw.write(">"); } fw.write(line); fw.write("\n"); } fw.write("\n"); r.close(); }
From source file:com.dm.estore.common.utils.FileUtils.java
/** * * @param inputStream Input stream to read data from. * @param outputName Target file name to write data in. */// w w w. j a va 2 s . c o m public static void saveFile(InputStream inputStream, String outputName) { OutputStreamWriter out = null; try { out = new OutputStreamWriter(new FileOutputStream(outputName), DEFAULT_ENCODING); final BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream)); String inputLine = inputReader.readLine(); while (inputLine != null) { out.append(inputLine); inputLine = inputReader.readLine(); if (inputLine != null) { out.append(NEW_LINE_SEP); } } inputReader.close(); } catch (Exception e) { LOG.error("Unable to write file: " + outputName, e); } finally { if (out != null) { try { out.close(); } catch (Exception e) { LOG.trace("Unable to close file: " + outputName, e); } } } }
From source file:com.eurotong.orderhelperandroid.Common.java
public static void SaveToIsolatedStorage(String fileContent, String fileName) throws Exception { //http://stackoverflow.com/questions/4228699/write-and-read-strings-to-from-internal-file FileOutputStream fos = MyApplication.getAppContext().openFileOutput(fileName, Context.MODE_PRIVATE); OutputStreamWriter osw = new OutputStreamWriter(fos, "Unicode"); osw.append(fileContent); osw.close();/*from w w w .j a v a 2 s . c o m*/ }
From source file:mitm.common.tools.SMIME.java
private static MimeMessage loadp7m(String filename, boolean binary) throws Exception { File p7mFile = new File(filename); p7mFile = p7mFile.getAbsoluteFile(); FileInputStream fis = new FileInputStream(p7mFile); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter sw = new OutputStreamWriter(bos); sw.append("Content-Type: application/pkcs7-mime; name=\"smime.p7m\"\r\n"); sw.append("Content-Transfer-Encoding: base64\r\n"); sw.append("\r\n\r\n"); byte[] content = IOUtils.toByteArray(fis); if (binary) { content = Base64.encodeBase64Chunked(content); }/*from ww w . j av a 2s . co m*/ String base64Content = MiscStringUtils.toAsciiString(content); sw.append(base64Content); sw.flush(); MimeMessage message = MailUtils.byteArrayToMessage(bos.toByteArray()); return message; }
From source file:org.csware.ee.utils.Tools.java
public static String GetDataByPost(String httpUrl, String parMap) { try {/* w w w. j av a 2 s . c o m*/ URL url = new URL(httpUrl);// HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); // ? connection.setRequestProperty("Accept", "application/json"); // ?? connection.setRequestProperty("Content-Type", "application/json"); // ???? connection.connect(); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8? out.append(parMap); out.flush(); out.close(); // ?? int length = (int) connection.getContentLength();// ? InputStream is = connection.getInputStream(); if (length != -1) { byte[] data = new byte[length]; byte[] temp = new byte[1024]; int readLen = 0; int destPos = 0; while ((readLen = is.read(temp)) > 0) { System.arraycopy(temp, 0, data, destPos, readLen); destPos += readLen; } String result = new String(data, "UTF-8"); // utf-8? return result; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("aa: " + e.getMessage()); } return "error"; // ? }
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsCSVInterceptor.java
private void writeCSV(String value, OutputStreamWriter w) throws IOException { w.append(value + ";"); }
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsCSVInterceptor.java
private void writeNewLine(OutputStreamWriter w) throws IOException { w.append(System.getProperty("line.separator")); }
From source file:org.glucosio.android.tools.ReadingToCSV.java
public Uri createCSV(final ArrayList<GlucoseReading> readings, String um) { File file = new File(context.getFilesDir().getAbsolutePath(), "glucosio_exported_data.csv"); //Getting a file within the dir. try {/*ww w .j a v a 2s.co m*/ FileOutputStream fileOutputStream = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fileOutputStream); osw.append(context.getResources().getString(R.string.dialog_add_concentration)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_measured)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_date)); osw.append(','); osw.append(context.getResources().getString(R.string.dialog_add_time)); osw.append('\n'); FormatDateTime dateTool = new FormatDateTime(context); if ("mg/dL".equals(um)) { for (int i = 0; i < readings.size(); i++) { osw.append(readings.get(i).getReading() + "mg/dL"); osw.append(','); osw.append(readings.get(i).getReading_type() + ""); osw.append(','); osw.append(dateTool.convertRawDate(readings.get(i).getCreated() + "")); osw.append(','); osw.append(dateTool.convertRawTime(readings.get(i).getCreated() + "")); osw.append('\n'); } } else { GlucosioConverter converter = new GlucosioConverter(); for (int i = 0; i < readings.size(); i++) { osw.append(converter.glucoseToMmolL(readings.get(i).getReading()) + "mmol/L"); osw.append(','); osw.append(dateTool.convertRawDate(readings.get(i).getCreated() + "")); osw.append(','); osw.append(dateTool.convertRawTime(readings.get(i).getCreated() + "")); osw.append('\n'); } } osw.flush(); osw.close(); Log.i("Glucosio", "Done exporting readings"); } catch (Exception e) { e.printStackTrace(); } context.grantUriPermission(context.getPackageName(), Uri.parse(file.getAbsolutePath()), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); return FileProvider.getUriForFile(context, context.getPackageName() + ".provider.fileprovider", file.getAbsoluteFile()); }
From source file:com.stratio.explorer.interpreter.InterpreterFactory.java
private void saveToFile(String file, String path) throws IOException { File settingFile = new File(path); if (!settingFile.exists()) { settingFile.createNewFile();//from ww w . j av a 2s . co m } FileOutputStream fos = new FileOutputStream(settingFile, false); OutputStreamWriter out = new OutputStreamWriter(fos); out.append(file); out.close(); fos.close(); }