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:com.zhch.example.commons.http.v4_5.ProxyTunnelDemo.java

/**
 * ?? demo/*from   w  w w . ja va  2 s.  co m*/
 * 
 * @throws Exception
 */
public final static void officalDemo() throws Exception {
    ProxyClient proxyClient = new ProxyClient();
    HttpHost target = new HttpHost("www.yahoo.com", 80);
    HttpHost proxy = new HttpHost("localhost", 8888);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd");
    Socket socket = proxyClient.tunnel(proxy, target, credentials);
    try {
        Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
        out.write("GET / HTTP/1.1\r\n");
        out.write("Host: " + target.toHostString() + "\r\n");
        out.write("Agent: whatever\r\n");
        out.write("Connection: close\r\n");
        out.write("\r\n");
        out.flush();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET));
        String line = null;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    } finally {
        socket.close();
    }
}

From source file:boxConnection.SerBoxTelnet.java

private static void createTelnetSession(String command) throws IOException, InterruptedException {
    telnet.connect(ControlMain.getActiveBox().getDboxIp());
    OutputStream ostream = telnet.getOutputStream();
    Writer writer = new OutputStreamWriter(ostream);
    writer.write(ControlMain.getActiveBox().getLogin() + "\n");
    writer.flush();//from w w  w.  j a v  a 2  s.  co m
    Thread.sleep(1000);
    writer.write(ControlMain.getActiveBox().getPassword() + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write(command + "\n");
    writer.flush();
    closeTelnetSession();
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step12GolDataExporter.java

/**
 * Serializes object to XML//from   www  .  ja v  a2s  .com
 *
 * @param object object
 * @return xml as string
 * @throws IOException exception
 */
public static String toXML(Object object) throws IOException {
    Writer out = new StringWriter();
    out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

    XStream xStream = getXStream();

    xStream.toXML(object, out);
    IOUtils.closeQuietly(out);

    return out.toString();
}

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static void sendJsonError(final HttpServletRequest request, final HttpServletResponse response,
        final int code, final JSONObject error) throws IOException, JSONException {
    setResponseContentTypeAndEncoding(request, response);
    response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
    response.setStatus(code);/*from  w  w w.  j a v a2  s .  c  om*/
    error.put("code", code);

    final Writer writer = response.getWriter();
    try {
        writer.write(error.toString());
        writer.write("\r\n");
    } finally {
        writer.close();
    }
}

From source file:com.zhch.example.commons.http.v4_5.ProxyTunnelDemo.java

/**
 *  demo  /*from   w  w w .ja  v a 2 s  .c  o m*/
 * 
 * @throws Exception
 */
public final static void zhchModifyDemo() throws Exception {

    ProxyClient proxyClient = new ProxyClient();
    HttpHost target = new HttpHost("pan.baidu.com", 80);
    //      HttpHost proxy = new HttpHost("120.24.0.162", 80);
    HttpHost proxy = new HttpHost("127.0.0.1", 80);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("abc", "def");
    System.out.println("before tunnel.");
    Socket socket = proxyClient.tunnel(proxy, target, credentials);
    System.out.println("after tunnel.");

    try {
        Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
        out.write("GET / HTTP/1.1\r\n");
        out.write("Host: " + target.toHostString() + "\r\n");
        out.write("Agent: whatever\r\n");
        out.write("Connection: close\r\n");
        out.write("\r\n");
        out.flush();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET));
        String line = null;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    } finally {
        socket.close();
    }
}

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

private static void writeHeader(HttpServletResponse resp) throws IOException {
    resp.setStatus(200);/*from www . ja va2 s  .c  om*/
    resp.setContentType("text/html;charset=UTF-8");
    Writer out = resp.getWriter();
    out.write("<h1>Loading&hellip;</h1>");
    out.flush();
}

From source file:Main.java

public final static void writeSimpleElementLine(Writer w, int deep, String element, String content)
        throws IOException {
    if (deep >= 0)
        writeDeep(w, deep);//from  w ww .j a va 2 s .c o  m
    w.write('<');
    w.write(element);
    w.write('>');
    w.write(content);
    w.write('<');
    w.write('/');
    w.write(element);
    w.write('>');
    w.write('\n');
}

From source file:ie.pars.bnc.preprocess.MainBNCProcess.java

private static void getZippedFile() throws IOException, ArchiveException, Exception {
    String taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";
    String parseModel = LexicalizedParser.DEFAULT_PARSER_LOC;

    InputStream is = new FileInputStream(pathInput);
    TarArchiveInputStream tarStream = (TarArchiveInputStream) new ArchiveStreamFactory()
            .createArchiveInputStream("tar", is);
    TarArchiveEntry entry = null;//  w ww.jav a2 s .  c  om
    int countfiles = 0;
    while ((entry = (TarArchiveEntry) tarStream.getNextEntry()) != null) {
        //     for(File lf: listFiles){ 
        if (!entry.isDirectory()) {

            byte[] content = new byte[(int) entry.getSize()];
            int offset = 0;
            tarStream.read(content, offset, content.length - offset);
            String id = entry.getName().split("/")[entry.getName().split("/").length - 1].split(".xml")[0];

            if (!filesProcesed.contains(id) && id.startsWith(letter.toUpperCase())) {
                if (countfiles++ % 10 == 0) {
                    tagger = new MaxentTagger(taggerPath);
                    m = new Morphology();
                    parser = ParserGrammar.loadModel(parseModel);
                    parser.loadTagger();
                }
                System.out.print("Entry " + entry.getName());

                InputStream bis = new ByteArrayInputStream(content);
                StringBuilder parseBNCXML = ProcessNLP.parseBNCXML(bis, m, tagger, parser);
                bis.close();
                OutputStream out = new FileOutputStream(pathOutput + File.separatorChar + id + ".vert");
                Writer writer = new OutputStreamWriter(out, "UTF-8");

                writer.write("<text id=\"" + id + "\">\n");
                writer.write(parseBNCXML.toString());
                writer.write("</text>\n");
                writer.close();
                out.close();
            } else {
                System.out.println(">> Bypass Entry " + entry.getName());
            }
            //break;
        }

    }
    is.close();
    System.out.println("There are " + countfiles);
    //    tarStream.close();

}

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

/**
 * Starts an inline stylesheet tag./* ww  w .j a va  2s  . c  o  m*/
 *
 * @param out the output writer
 * @throws IOException if the code could not be written
 */
public static void beginStyleSheet(Writer out) throws IOException {
    out.write("<style type=\"text/css\">\n");
}

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

/**
 * Ends an inline stylesheet tag.//from  w  w w .  j av  a  2 s. co  m
 *
 * @param out the output writer
 * @throws IOException if the code could not be written
 */
public static void endStyleSheet(Writer out) throws IOException {
    out.write("\n</style>\n");
}