public void appendLn() throws IOException { stream.append("\n"); isFirstData = true; }
@Override public Writer append(CharSequence text) throws IOException { return super.append(((String)text).replace("\n", newline).replace("\\u", "\\u005Cu")); } }
public void appendLn(String value) throws IOException { append(value); stream.append("\n"); isFirstData = true; }
public static void writeUtf8File(@Nullable String outputDir, String fileName, XMLStringBuffer xsb, String prefix) { try { final File outDir = (outputDir != null) ? new File(outputDir) : new File("").getAbsoluteFile(); if (!outDir.exists()) { outDir.mkdirs(); } final File file = new File(outDir, fileName); if (!file.exists()) { file.createNewFile(); } try (final OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) { if (prefix != null) { w.append(prefix); } xsb.toWriter(w); } } catch(IOException ex) { LOG.error(ex.getMessage(), ex); } }
private void writeTestFile(File file) { File parent = file.getAbsoluteFile().getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { logger.warn("Couldn't create directory: {}", parent); } } try (FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8.name())) { osw.append(sb); } catch (FileNotFoundException e) { logger.error("Failed to open test file ({}).", file, e); } catch (UnsupportedEncodingException e) { logger.error("Failed to open writer.", e); } catch (IOException e) { logger.error("Failed to write test file ({}).", file, e); } }
public static void writeUtf8File( @Nullable String outputDir, String fileName, XMLStringBuffer xsb, String prefix) { try { final File outDir = (outputDir != null) ? new File(outputDir) : new File("").getAbsoluteFile(); if (!outDir.exists()) { outDir.mkdirs(); } final File file = new File(outDir, fileName); if (!file.exists()) { file.createNewFile(); } try (final OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { if (prefix != null) { w.append(prefix); } xsb.toWriter(w); } } catch (IOException ex) { LOG.error(ex.getMessage(), ex); } }
writer.append((CharSequence) t); writer.flush(); return;
if (req.endsWith("MultiEnt")) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 2\n" + "Content-Length: 1\n" + "\n0\n"); outputStreamWriter.flush(); } else if (req.endsWith("MultiOther")) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 1\n" + "X-Forwarded-For: abc\n" + "X-Forwarded-For: def\n" + "\n0\n"); outputStreamWriter.flush();
writer.append(body);
/** Writes given string to given stream, using given charset */ public static void writeStringToStream(String string, OutputStream stream, Charset charset) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(stream, charset); try { osw.append(string); osw.flush(); } finally { osw.close(); } }
@Override public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException { if (!isAvailable() || !checkCommand(buildCheckCommand(smtPath), 1)) return text; File tmpFile = new File(TMP_FILE_NAME); @SuppressWarnings("resource") OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile), Charset.defaultCharset()); out.append(text).append('\n').close(); Runtime.getRuntime().exec(buildCommand(smtPath, scriptPath), new String[]{}, buildWorkingDirectory(scriptPath)); File tmpTranslatedFile = new File(TMP_FILE_NAME + ".translated"); StringBuilder stringBuilder = new StringBuilder(); @SuppressWarnings("resource") BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(tmpTranslatedFile), Charset.defaultCharset() )); String line; while ((line = reader.readLine()) != null) stringBuilder.append(line); if (!tmpFile.delete() || !tmpTranslatedFile.delete()){ throw new IOException("Failed to delete temporary files."); } return stringBuilder.toString(); }
osw.append(ExportTable.EXPORT_VERSION_PROP + ":" + ExportTable.VERSION + "\n"); osw.append("srcInstanceName:" + context.getInstanceName() + "\n"); osw.append("srcInstanceID:" + context.getInstanceID() + "\n"); osw.append("srcTableName:" + tableName + "\n"); osw.append("srcTableID:" + tableID.canonicalID() + "\n"); osw.append(ExportTable.DATA_VERSION_PROP + ":" + ServerConstants.DATA_VERSION + "\n"); osw.append("srcCodeVersion:" + Constants.VERSION + "\n");
public static boolean exportRules(Context ctx, final String fileName) { boolean res = false; File sdCard = Environment.getExternalStorageDirectory(); if (isExternalStorageWritable()) { File dir = new File(sdCard.getAbsolutePath() + "/afwall/"); dir.mkdirs(); File file = new File(dir, fileName); try { FileOutputStream fOut = new FileOutputStream(file); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); //default Profile - current one JSONObject obj = new JSONObject(getCurrentRulesAsMap(ctx)); JSONArray jArray = new JSONArray("[" + obj.toString() + "]"); myOutWriter.append(jArray.toString()); res = true; myOutWriter.close(); fOut.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getLocalizedMessage()); } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, e.getLocalizedMessage()); } } return res; }
myOutWriter.append(exportObject.toString()); res = true; myOutWriter.close();
/** Writes given string to given stream, using given charset */ public static void writeStringToStream(String string, OutputStream stream, Charset charset) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(stream, charset); try { osw.append(string); osw.flush(); } finally { osw.close(); } }