Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

In this page you can find the example usage for java.io Writer write.

Prototype

public void write(String str) throws IOException 

Source Link

Document

Writes a string.

Usage

From source file:Main.java

public static void write(byte[] data, Writer output) throws IOException {
    if (data != null)
        output.write(new String(data));
}

From source file:Main.java

public static void write(char[] data, Writer output) throws IOException {
    if (data != null)
        output.write(data);
}

From source file:Main.java

public static void write(CharSequence data, Writer output) throws IOException {
    if (data != null)
        output.write(data.toString());
}

From source file:com.flexive.faces.javascript.FxJavascriptUtils.java

/**
 * Write dojo "require" calls for all requested components.
 *
 * @param out      the output writer/*from  ww  w  . j  a v  a  2  s. c  om*/
 * @param packages array of packages to be written (e.g. "dojo.widget.*")
 * @throws IOException if the code could not be written
 */
public static void writeDojoRequires(Writer out, String... packages) throws IOException {
    for (String pkg : packages) {
        out.write("dojo.require(\"" + pkg + "\");\n");
    }
}

From source file:com.flexive.faces.javascript.FxJavascriptUtils.java

/**
 * Write Yahoo require calls for all requested components.
 *
 * @param out      the output writer//  w ww. j a v a  2  s .co  m
 * @param packages array of componentsto be written (e.g. "button")
 * @throws IOException if the code could not be written
 */
public static void writeYahooRequires(Writer out, String... packages) throws IOException {
    for (String pkg : packages) {
        out.write("flexive.yui.require(\"" + pkg + "\");\n");
    }
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.TextsResumeToJson.java

private static void saveResults(JSONArray recomendations, String id) {
    Writer out;
    try {/*from   ww  w.  ja  v a2 s  .  c om*/
        out = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream("data_toVisualize/data_resume/resume_" + id + ".json"), "UTF-8"));

        try {
            out.write(recomendations.toJSONString());
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.linkedin.restli.datagenerator.csharp.CSharpRythmGenerator.java

private static void writeToFile(File file, String content) throws IOException {
    Writer fileWriter = null;
    try {/* www.  j  a  v a 2 s  . com*/
        fileWriter = new BufferedWriter(new FileWriter(file));
        fileWriter.write(content);
    } finally {
        if (fileWriter != null) {
            fileWriter.close();
        }
    }
}

From source file:com.google.caja.ancillary.servlet.UploadPage.java

static void doUpload(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    // Process the uploaded items
    List<ObjectConstructor> uploads = Lists.newArrayList();

    if (ServletFileUpload.isMultipartContent(req)) {
        // Create a factory for disk-based file items
        DiskFileItemFactory factory = new DiskFileItemFactory();

        int maxUploadSizeBytes = 1 << 18;
        factory.setSizeThreshold(maxUploadSizeBytes); // In-memory threshold
        factory.setRepository(new File("/dev/null")); // Do not store on disk
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(maxUploadSizeBytes);

        writeHeader(resp);/*from w  w  w. j a v  a  2  s  . com*/

        // Parse the request
        List<?> items;
        try {
            items = upload.parseRequest(req);
        } catch (FileUploadException ex) {
            ex.printStackTrace();
            resp.getWriter().write(Nodes.encode(ex.getMessage()));
            return;
        }

        for (Object fileItemObj : items) {
            FileItem item = (FileItem) fileItemObj; // Written for pre-generic java.
            if (!item.isFormField()) { // Then is a file
                FilePosition unk = FilePosition.UNKNOWN;
                String ct = item.getContentType();
                uploads.add((ObjectConstructor) QuasiBuilder.substV("({ i: @i, ip: @ip, it: @it? })", "i",
                        StringLiteral.valueOf(unk, item.getString()), "ip",
                        StringLiteral.valueOf(unk, item.getName()), "it",
                        ct != null ? StringLiteral.valueOf(unk, ct) : null));
            }
        }
    } else if (req.getParameter("url") != null) {
        List<URI> toFetch = Lists.newArrayList();
        boolean failed = false;
        for (String value : req.getParameterValues("url")) {
            try {
                toFetch.add(new URI(value));
            } catch (URISyntaxException ex) {
                if (!failed) {
                    failed = true;
                    resp.setStatus(500);
                    resp.setContentType("text/html;charset=UTF-8");
                }
                resp.getWriter().write("<p>Bad URI: " + Nodes.encode(ex.getMessage()));
            }
        }
        if (failed) {
            return;
        }
        writeHeader(resp);
        FilePosition unk = FilePosition.UNKNOWN;
        for (URI uri : toFetch) {
            try {
                Content c = UriFetcher.fetch(uri);
                if (c.isText()) {
                    uploads.add((ObjectConstructor) QuasiBuilder.substV("({ i: @i, ip: @ip, it: @it? })", "i",
                            StringLiteral.valueOf(unk, c.getText()), "ip",
                            StringLiteral.valueOf(unk, uri.toString()), "it",
                            StringLiteral.valueOf(unk, c.type.mimeType)));
                }
            } catch (IOException ex) {
                resp.getWriter()
                        .write("<p>" + Nodes.encode("Failed to fetch URI: " + uri + " : " + ex.getMessage()));
            }
        }
    } else {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        resp.getWriter().write("Content not multipart");
        return;
    }

    Expression notifyParent = (Expression) QuasiBuilder.substV(
            "window.parent.uploaded([@uploads*], window.name)", "uploads", new ParseTreeNodeContainer(uploads));
    StringBuilder jsBuf = new StringBuilder();
    RenderContext rc = new RenderContext(new JsMinimalPrinter(new Concatenator(jsBuf))).withEmbeddable(true);
    notifyParent.render(rc);
    rc.getOut().noMoreTokens();

    HtmlQuasiBuilder b = HtmlQuasiBuilder.getBuilder(DomParser.makeDocument(null, null));

    Writer out = resp.getWriter();
    out.write(Nodes.render(b.substV("<script>@js</script>", "js", jsBuf.toString())));
}

From source file:me.timothy.ddd.DDDUtils.java

public static void writeJSONPretty(Writer out, Map<?, ?> map, int indentation) throws IOException {
    out.write('{');
    indentation++;/*from  w ww .  j a  v a 2  s  .  c o  m*/
    boolean first = true;
    Set<?> keys = map.keySet();
    for (Object o : keys) {
        if (!(o instanceof String)) {
            throw new IllegalArgumentException("Invalid key: " + o.getClass().getName());
        }

        String str = (String) o;
        if (!first) {
            out.write(',');
        } else {
            first = false;
        }
        out.write('\n');
        writeIndentation(out, indentation);
        write(out, str, indentation);
        out.write(": ");
        Object val = map.get(o);
        write(out, val, indentation);
    }
    indentation--;
    out.write('\n');
    writeIndentation(out, indentation);
    out.write('}');
}

From source file:DocWriter.java

private static void serializeNode(Node node, Writer out, String indent) throws IOException {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_NODE:
        out.write("<?xml version=\"1.0\"?>" + '\n');
        writeNode(((Document) node).getDocumentElement(), out, indent);
        break;//w  w  w . ja  va2s  . c  o  m
    case Node.ELEMENT_NODE:
        writeNode(node, out, indent);
        break;
    case Node.TEXT_NODE:
        out.write(node.getNodeValue());
        break;
    case Node.COMMENT_NODE:
        out.write( /*indent + */ "<!--" + node.getNodeValue() + "-->");
        break;
    default:
        System.out.println("Got node: " + node.getNodeName());
        break;
    }
}