List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:org.bigloupe.web.monitor.util.JSONUtil.java
/** * Writes object to the writer as JSON using Jackson and adds a new-line * before flushing./*from ww w .j a v a 2 s . c o m*/ * * @param writer * the writer to write the JSON to * @param object * the object to write as JSON * @throws IOException * if the object can't be serialized as JSON or written to the * writer */ public static void writeJson(Writer writer, Object object) throws IOException { ObjectMapper om = new ObjectMapper(); om.enable(SerializationFeature.INDENT_OUTPUT); om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); writer.write(om.writeValueAsString(object)); writer.write("\n"); writer.flush(); }
From source file:jp.igapyon.diary.v3.util.IgapyonV3Util.java
public static void writePreHtml(final IgapyonMd2HtmlSettings settings, final IgapyonPegDownTagConf tagConf, final Writer writer, final String mdStringHead, final String author) throws IOException { writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.write(/*from ww w . j ava2s. co m*/ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"); // FIXME lang should be variable writer.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" lang=\"ja\">"); writer.write("<head>\n"); writer.write("<meta charset=\"utf-8\">\n"); writer.write("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"); writer.write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"); writer.write("<meta name=\"description\" content=\"" + settings.getHtmlDescription() + "\">\n"); writer.write("<meta name=\"author\" content=\"" + author + "\">\n"); writer.write("<meta name=\"generator\" content=\"" + IgapyonMd2HtmlConstants.PROGRAM_DISPLAY_NAME + " ver" + IgapyonMd2HtmlConstants.VERSION + "\">\n"); writer.write("<title>" + settings.getHtmlTitle() + "</title>\n"); writer.write("<!-- Compiled and minified CSS -->\n"); writer.write( "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n"); // see: http://getbootstrap.com/examples/theme/ // try to remove optional theme // writer.write("<!-- Optional theme -->\n"); // writer.write("<link rel=\"stylesheet\" // href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css\">\n"); writer.write("</head>\n"); writer.write("<body>\n"); // Use container-fluid instead container. writer.write("<div class=\"container-fluid\">\n"); writer.write("<div class=\"jumbotron\">\n"); if (mdStringHead.length() > 0) { final String bodyMarkdown = simpleMd2Html(settings, tagConf, mdStringHead, new IgapyonLinkRenderer()); writer.write(bodyMarkdown); } writer.write("</div>\n"); // TODO container should be outside. writer.write("<div class=\"container-fluid\">\n"); }
From source file:com.prowidesoftware.swift.io.PPCWriter.java
/** * Writes the message content into the writer in DOS-PPC format * @param msg SWIFT MT content to write/*from w ww . j a v a 2 s .com*/ * @param writer * @throws IOException if an I/O error occurs */ /* * According to the specification content should be written in 8-bit ASCII * We use Java default, UTF-8, that is compatible for SWIFT message content. */ public static void write(final String msg, final Writer writer) throws IOException { Validate.notNull(writer, "writer has not been initialized"); Validate.notNull(msg, "message to write cannot be null"); writer.write(PPCReader.BEGIN); writer.write(msg); writer.write(PPCReader.END); /* * pad to fill sector length */ int length = msg.length() + 2; int pad = length > 512 ? length % 512 : 512 - length; for (int i = 0; i < pad; i++) { writer.write(PPCReader.EMPTY); } }
From source file:Main.java
public static void writeEscapedString(Writer writer, String value) throws IOException { for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if ((c >= ' ') && (c < 0x7f)) { if ((c == '\'') || (c == '\"') || (c == '\\')) { writer.write('\\'); }/*ww w. j ava2 s .co m*/ writer.write(c); continue; } else if (c <= 0x7f) { switch (c) { case '\n': writer.write("\\n"); continue; case '\r': writer.write("\\r"); continue; case '\t': writer.write("\\t"); continue; } } writer.write("\\u"); writer.write(Character.forDigit(c >> 12, 16)); writer.write(Character.forDigit((c >> 8) & 0x0f, 16)); writer.write(Character.forDigit((c >> 4) & 0x0f, 16)); writer.write(Character.forDigit(c & 0x0f, 16)); } }
From source file:net.sf.zekr.common.util.ConfigUtils.java
@SuppressWarnings("unchecked") public static void write(Configuration configuration, Writer w) throws IOException { Iterator keys = configuration.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); Object value = configuration.getProperty(key); w.write(key); w.write(" = "); if (value instanceof Collection) { w.write(CollectionUtils.toString((List) value, ", ")); } else {/*from w ww . j a v a 2 s .c o m*/ w.write(ObjectUtils.toString(value)); } if (keys.hasNext()) { w.write(GlobalConfig.LINE_SEPARATOR); } } }
From source file:jsdp.app.lotsizing.sS_jsdp.java
public static void plotCostFunction(int targetPeriod, double fixedOrderingCost, double proportionalOrderingCost, double holdingCost, double penaltyCost, Distribution[] distributions, double minDemand, double maxDemand, boolean printCostFunctionValues, boolean latexOutput, sS_StateSpaceSampleIterator.SamplingScheme samplingScheme, int maxSampleSize) { sS_BackwardRecursion recursion = new sS_BackwardRecursion(distributions, minDemand, maxDemand, fixedOrderingCost, proportionalOrderingCost, holdingCost, penaltyCost, samplingScheme, maxSampleSize);/*ww w . j a v a 2 s.com*/ recursion.runBackwardRecursion(targetPeriod); XYSeries series = new XYSeries("(s,S) policy"); for (double i = sS_State.getMinInventory(); i <= sS_State.getMaxInventory(); i += sS_State.getStepSize()) { sS_StateDescriptor stateDescriptor = new sS_StateDescriptor(targetPeriod, sS_State.inventoryToState(i)); series.add(i, recursion.getExpectedCost(stateDescriptor)); if (printCostFunctionValues) System.out.println(i + "\t" + recursion.getExpectedCost(stateDescriptor)); } XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "(s,S) policy - period " + targetPeriod + " expected total cost", "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true, false); ChartFrame frame = new ChartFrame("(s,S) policy", chart); frame.setVisible(true); frame.setSize(500, 400); if (latexOutput) { try { XYLineChart lc = new XYLineChart("(s,S) policy", "Opening inventory level", "Expected total cost", new XYSeriesCollection(series)); File latexFolder = new File("./latex"); if (!latexFolder.exists()) { latexFolder.mkdir(); } Writer file = new FileWriter("./latex/graph.tex"); file.write(lc.toLatex(8, 5)); file.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
public static String highlight(final List<String> lines, final String meta, final String prog, final String encoding) throws IOException { final File tmpIn = new File(System.getProperty("java.io.tmpdir"), String.format("txtmark_code_%d_%d.in", ID, IN_COUNT.incrementAndGet())); final File tmpOut = new File(System.getProperty("java.io.tmpdir"), String.format("txtmark_code_%d_%d.out", ID, OUT_COUNT.incrementAndGet())); try {//from w w w . j a va2s. c om final Writer w = new OutputStreamWriter(new FileOutputStream(tmpIn), encoding); try { for (final String s : lines) { w.write(s); w.write('\n'); } } finally { w.close(); } final List<String> command = new ArrayList<String>(); command.add(prog); command.add(meta); command.add(tmpIn.getAbsolutePath()); command.add(tmpOut.getAbsolutePath()); final ProcessBuilder pb = new ProcessBuilder(command); final Process p = pb.start(); final InputStream pIn = p.getInputStream(); final byte[] buffer = new byte[2048]; int exitCode = 0; for (;;) { if (pIn.available() > 0) { pIn.read(buffer); } try { exitCode = p.exitValue(); } catch (final IllegalThreadStateException itse) { continue; } break; } if (exitCode == 0) { final Reader r = new InputStreamReader(new FileInputStream(tmpOut), encoding); try { final StringBuilder sb = new StringBuilder(); for (;;) { final int c = r.read(); if (c >= 0) { sb.append((char) c); } else { break; } } return sb.toString(); } finally { r.close(); } } throw new IOException("Exited with exit code: " + exitCode); } finally { tmpIn.delete(); tmpOut.delete(); } }
From source file:com.cloudhopper.sxmp.SxmpWriter.java
static private void writeRequestResponseEndTag(Writer out, Operation operation) throws IOException { out.write(" </"); writeRequestResponseTag(out, operation); out.write(">\n"); }
From source file:com.cloudhopper.sxmp.SxmpWriter.java
static private void writeErrorElement(Writer out, Response response) throws IOException { out.write(" <error code=\""); out.write(response.getErrorCode().toString()); out.write("\" message=\""); out.write(StringUtil.escapeXml(response.getErrorMessage())); out.write("\"/>\n"); }
From source file:Base64.java
private static void writeChars(final File file, final char[] data) { try {/*from ww w .j ava 2s .co m*/ final Writer fos = new FileWriter(file); final Writer os = new BufferedWriter(fos); os.write(data); os.close(); } catch (Exception e) { e.printStackTrace(); } }