List of usage examples for java.io OutputStreamWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:lohbihler.process.Test.java
public static void main(final String[] args) throws Exception { final ExecutorService executorService = Executors.newCachedThreadPool(); final Process process = new ProcessBuilder("cmd").start(); final InputReader input = new InputReader(process.getInputStream()); final InputReader error = new InputReader(process.getErrorStream()); executorService.execute(input);//www . j a v a 2 s. c om executorService.execute(error); final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream()); Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); out.append("PING 1.1.1.1 -n 1 -w 5000\r\n"); out.flush(); for (int i = 0; i < 7; i++) { Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); } out.append("PING 1.1.1.1 -n 1 -w 2000\r\n"); out.flush(); for (int i = 0; i < 4; i++) { Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); } process.destroy(); executorService.shutdown(); }
From source file:Main.java
public static void logToFile(String filename, String log) { File myFile = new File("/sdcard/SAGETablet/" + filename + ".txt"); try {/* w w w . ja v a2s .c om*/ if (!myFile.exists()) { myFile.createNewFile(); } FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(log); myOutWriter.close(); fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
private static void writeToOutputStreamArray(String[] array, OutputStreamWriter oswriter) { for (int i = 0; i < array.length; i++) { try {/*from www. j av a 2 s. c o m*/ oswriter.append(array[i] + " "); } catch (IOException e) { e.printStackTrace(); } } try { oswriter.append("\n"); oswriter.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
private static void writeToOutputStreamArray(String[] array, OutputStreamWriter oswriter) { for (int i = 0; i < array.length; i++) { try {/*from w w w .ja v a 2 s . co m*/ oswriter.append(array[i] + " "); } catch (IOException e) { e.printStackTrace(); } } try { oswriter.append("\n\n"); oswriter.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.htrace.viewer.HBaseSpanViewer.java
public static void appendJsonString(final Message message, OutputStreamWriter writer) throws IOException { writer.append("{"); for (Iterator<Map.Entry<FieldDescriptor, Object>> iter = message.getAllFields().entrySet().iterator(); iter .hasNext();) {/*from www . j av a2 s. co m*/ Map.Entry<FieldDescriptor, Object> field = iter.next(); appendFields(field.getKey(), field.getValue(), writer); if (iter.hasNext()) { writer.append(","); } } writer.append("}"); }
From source file:org.apache.htrace.viewer.HBaseSpanViewer.java
private static void appendFields(FieldDescriptor fd, Object value, OutputStreamWriter writer) throws IOException { writer.append("\""); writer.append(fd.getName());/*w ww.ja v a 2s . c om*/ writer.append("\""); writer.append(":"); if (fd.isRepeated()) { writer.append("["); for (Iterator<?> it = ((List<?>) value).iterator(); it.hasNext();) { appendValue(fd, it.next(), writer); if (it.hasNext()) { writer.append(","); } } writer.append("]"); } else { appendValue(fd, value, writer); } }
From source file:eionet.cr.web.util.TriplesToOutputStream.java
/** * * @param out// w w w.j a v a 2 s .co m * @param subjectUri * @param triples */ public static void triplesToHtml(OutputStream out, String subjectUri, List<SubjectDTO> triples) { OutputStreamWriter writer = new OutputStreamWriter(out); try { writer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-gb\">"); writer.append("<head>"); writer.append("<title>").append(subjectUri).append("</title>"); writer.append("<link rel=\"alternate\" type=\"application/rdf+xml\" href=\"").append(subjectUri) .append("\" />"); writer.append("<style type=\"text/css\">" + "/*<![CDATA[*/ " + "table { border: 1px solid black; border-collapse:collapse; } " + "td, th { border: 1px solid black; padding: 0.3em; } " + "/*]]>*/" + "</style>"); writer.append("</head>"); writer.append("<body>"); writer.append("<h1>").append(subjectUri).append("</h1>"); writer.append("<table>"); writer.append("<tr><th>Subject</th><th>Predicate</th><th>Value</th></tr>"); if (triples != null) { for (SubjectDTO subject : triples) { Map<String, Collection<ObjectDTO>> predicates = subject.getPredicates(); if (predicates != null) { for (String predicateUri : predicates.keySet()) { Collection<ObjectDTO> objects = predicates.get(predicateUri); if (objects != null) { for (ObjectDTO object : objects) { writer.append("<tr>"); writer.append("<td>"); writer.append("<a href=\"").append(subject.getUri()).append("\">"); writer.append(subject.getUri()); writer.append("</a>"); writer.append("</td>"); writer.append("<td>").append(predicateUri).append("</td>"); writer.append("<td>"); if (object.isLiteral()) { writer.append(object.getValue()); } else { writer.append("<a href=\"").append(object.getValue()).append("\">") .append(object.getValue()).append("</a>"); } writer.append("</td>"); writer.append("</tr>"); } } } } } /* * for (TripleDTO triple : triples) { writer.append("<tr>"); * writer.append("<td>").append(triple.getSubjectUri()).append("</td>"); * writer.append("<td>").append(triple.getPredicateUri()).append("</td>"); * writer.append("<td>").append(triple.getObject()).append("</td>"); writer.append("</tr>"); } */ } writer.append("</table>"); writer.append("</body>"); writer.append("</html>"); writer.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { writer.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:eionet.cr.web.util.TriplesToOutputStream.java
/** * * @param out//from w w w.j a v a 2s. co m * @param subjectUri * @param triples */ public static void triplesToRdf(OutputStream out, String subjectUri, List<SubjectDTO> triples) { OutputStreamWriter writer = new OutputStreamWriter(out); try { if (triples != null) { writer.append(RDF_HEADER); writer.append("<rdf:RDF xmlns=\"").append(subjectUri + "#").append("\" xmlns:rdf=\"") .append(RDF_NAMESPACE).append("\" ").append("xmlns:rdfs=\"").append(RDFS_NAMESPACE) .append("\">"); for (SubjectDTO subject : triples) { writer.append("<rdf:Description rdf:about=\"") .append(StringEscapeUtils.escapeXml(subject.getUri())).append("\">"); Map<String, Collection<ObjectDTO>> predicates = subject.getPredicates(); if (predicates != null) { for (String predicateUri : predicates.keySet()) { Collection<ObjectDTO> objects = predicates.get(predicateUri); // Shorten predicate URIs if (predicateUri.startsWith(RDF_NAMESPACE)) { predicateUri = predicateUri.replace(RDF_NAMESPACE, "rdf:"); } else if (predicateUri.startsWith(RDFS_NAMESPACE)) { predicateUri = predicateUri.replace(RDFS_NAMESPACE, "rdfs:"); } else if (predicateUri.startsWith(subjectUri)) { predicateUri = predicateUri.replace(subjectUri + "#", ""); } if (objects != null) { for (ObjectDTO object : objects) { if (object.isLiteral()) { writer.append("<").append(predicateUri).append(">") .append(StringEscapeUtils.escapeXml(object.getValue())).append("</") .append(predicateUri).append(">"); } else { writer.append("<").append(predicateUri).append(" rdf:resource=\"") .append(StringEscapeUtils.escapeXml(object.getValue())) .append("\"/>"); } } } } } writer.append("</rdf:Description>"); } writer.append("</rdf:RDF>"); writer.flush(); } } catch (Exception e) { e.printStackTrace(); } finally { try { writer.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.htrace.viewer.HBaseSpanViewer.java
private static void appendValue(FieldDescriptor fd, Object value, OutputStreamWriter writer) throws IOException { switch (fd.getType()) { case INT64: // write int as string for handling in javascript case STRING://from w ww .j a va 2 s .c o m writer.append("\""); writer.append(value.toString()); writer.append("\""); break; case MESSAGE: appendJsonString((Message) value, writer); break; default: throw new IOException("unexpected field type."); } }
From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java
public static void append(String content, OutputStreamWriter outputStreamWriter) { try {/*w w w . j a va2 s .c o m*/ outputStreamWriter.append(content); } catch (IOException e) { throw new UncheckedIOException(e); } }