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.apress.progwt.server.web.controllers.SimpleAnnotatedController.java

/**
 * this is the gwtLoginTargetURL. When GWT does a form based login, it
 * will redirect here. GWT can then read this 'ok' in to know that it
 * was ok./*from w w w.  j a  v  a2  s.c  o m*/
 * 
 * @param w
 * @throws IOException
 */
@RequestMapping("/secure/gwtLoginOK.html")
public void gwtLoginHandler(Writer w) throws IOException {
    w.write("OK");
    w.close();
}

From source file:net.cit.tetrad.resource.CommandResource.java

@RequestMapping("/runCommamd.do")
public void loginView(HttpServletResponse response, CommonDto dto) throws Exception {
    Map<String, Object> serverStatusFromMongo = new HashMap<String, Object>();
    serverStatusFromMongo = comandService.insertCommand(dto.getDeviceCode(), dto.getMemo());

    List<Object> arrTotInfo = new ArrayList<Object>();
    arrTotInfo.add(serverStatusFromMongo);

    PersonJson result = new PersonJson();
    result.setAaData(arrTotInfo);//from w w w  .  ja  v  a  2s.c o  m

    JSONObject jsonObject = JSONObject.fromObject(result);

    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");

    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");

    Writer writer = response.getWriter();
    writer.write(jsonObject.toString());

    writer.flush();
}

From source file:com.moss.posixfifosockets.impl.HandlerThread.java

public void run() {
    try {/*from   ww w.  j a  va2 s  .c  o  m*/
        File in = new File(socketsDirectory, id + ".fifo.in");
        File out = new File(socketsDirectory, id + ".fifo.out");
        File control = new File(socketsDirectory, id + ".fifo.control");

        PosixFifoSocket.createFifo(in);

        {// LET THE CLIENT KNOW THAT THE CONNECTION HAS BEEN ESTABLISHED
            if (!out.exists()) {
                throw new RuntimeException(
                        "ERROR: FILE SHOULD HAVE BEEEN CREATED BY SOCKET CLIENT: " + out.getAbsolutePath());
            }
            if (!control.exists()) {
                throw new RuntimeException(
                        "ERROR: FILE SHOULD HAVE BEEEN CREATED BY SOCKET CLIENT: " + out.getAbsolutePath());
            }
            Writer w = new FileWriter(control);
            w.write("OK\n");
            w.close();
        }

        PosixFifoSocket socket = new PosixFifoSocket(id, in, out);

        if (log.isDebugEnabled())
            log.debug("Opened socket " + socket);
        handler.handle(socket);
        socket.close();

    } catch (Throwable e) {
        this.e = e;
        log.error("Error creating socket: " + e.getMessage(), e);
    } finally {
        if (debug != null) {
            debug.wentInactive(this);
        }

        //            handlers.remove(this);
        //            recentHandlers.add(this);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.json.JsonObjectProducer.java

public final void process(HttpServletResponse resp) throws IOException {
    JSONObject jsonObject = null;//  w  ww.jav a2  s .c o  m
    String errorMessage = "";

    try {
        jsonObject = process();
    } catch (Exception e) {
        log.error("Failed to create JSON response", e);
        errorMessage = e.toString();
        resp.setStatus(500 /* HttpURLConnection.HTTP_SERVER_ERROR */);
    }

    if (jsonObject == null) {
        jsonObject = new JSONObject();
    }

    log.debug("Response to JSON request: " + jsonObject.toString());

    try {
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8");
        Writer writer = resp.getWriter();

        jsonObject.put("errorMessage", errorMessage);
        writer.write(jsonObject.toString());
    } catch (JSONException e) {
        log.error(e, e);
    }
}

From source file:com.openkm.util.impexp.RepositoryChecker.java

/**
 * Read document contents./*from w  w w . j a  va2  s . co m*/
 */
private static ImpExpStats readDocument(String token, String docPath, boolean versions, Writer out,
        InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException {
    log.debug("readDocument({})", docPath);
    DocumentModule dm = ModuleManager.getDocumentModule();
    File fsPath = new File(Config.NULL_DEVICE);
    ImpExpStats stats = new ImpExpStats();
    Document doc = dm.getProperties(token, docPath);

    try {
        FileOutputStream fos = new FileOutputStream(fsPath);
        InputStream is = dm.getContent(token, docPath, false);
        IOUtils.copy(is, fos);
        is.close();

        if (versions) { // Check version history
            for (Version ver : dm.getVersionHistory(token, docPath)) {
                is = dm.getContentByVersion(token, docPath, ver.getName());
                IOUtils.copy(is, fos);
                is.close();
            }
        }

        fos.close();
        out.write(deco.print(docPath, doc.getActualVersion().getSize(), null));
        out.flush();

        // Stats
        stats.setSize(stats.getSize() + doc.getActualVersion().getSize());
        stats.setDocuments(stats.getDocuments() + 1);
    } catch (RepositoryException e) {
        log.error(e.getMessage());
        stats.setOk(false);
        out.write(deco.print(docPath, doc.getActualVersion().getSize(), e.getMessage()));
        out.flush();
    }

    return stats;
}

From source file:com.seyren.core.service.notification.IrcCatNotificationService.java

private void sendMessage(String ircCatHost, int ircCatPort, String message, String channel) throws IOException {
    Socket socket = new Socket(ircCatHost, ircCatPort);
    Closer closer = Closer.create();/*from   w  w  w.  ja  va  2 s .co  m*/
    try {
        Writer out = closer.register(new OutputStreamWriter(socket.getOutputStream()));
        out.write(format("%s %s\n", channel, message));
        out.flush();
    } catch (IOException e) {
        socket.close();
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}

From source file:org.esupportail.nfctagdroid.requestasync.CsnHttpRequestAsync.java

protected String doInBackground(String... params) {

    CsnMessageBean nfcMsg = new CsnMessageBean();
    nfcMsg.setNumeroId(LocalStorage.getValue("numeroId"));
    nfcMsg.setCsn(params[0]);/*ww w .j a  v a  2  s .c  o m*/
    ObjectMapper mapper = new ObjectMapper();
    String jsonInString = null;
    try {
        jsonInString = mapper.writeValueAsString(nfcMsg);
        URL url = new URL(NfcTacDroidActivity.ESUP_NFC_TAG_SERVER_URL + "/csn-ws");
        log.info("Will call csn-ws on : " + url);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
        conn.connect();
        Writer writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
        writer.write(jsonInString);
        writer.close();
        InputStream inputStream = conn.getInputStream();
        String response = "";
        String line;
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        while ((line = br.readLine()) != null) {
            response += line;
        }
        conn.disconnect();
        return response;
    } catch (Exception e) {
        throw new NfcTagDroidException(e);
    }
}

From source file:com.google.mr4c.content.AbstractContentFactory.java

public void writeContent(URI uri, String text) throws IOException {
    Writer writer = getWriterForContent(uri);
    try {/*from  w w  w . j  av  a  2 s . c om*/
        writer.write(text);
    } finally {
        writer.close();
    }
}

From source file:net.cit.tetrad.resource.CommandResource.java

@RequestMapping("/daemonDetailServerStatus.do")
public void daemonDetailServerStatus(HttpServletResponse response, CommonDto dto) throws Exception {
    String serverStatusFromMongo = comandService.allServerStatus(dto.getDeviceCode());
    JSONObject jsonObj = JSONObject.fromObject(JSONSerializer.toJSON(serverStatusFromMongo));
    JSONObject recordStats = (JSONObject) jsonObj.get("recordStats");
    if (recordStats != null) {
        Object ok = jsonObj.get("ok");
        jsonObj.remove("recordStats");
        jsonObj.remove("ok");

        Object accessNotInMemory = recordStats.get("accessesNotInMemory");
        Object pageFaultExceptionsThrown = recordStats.get("pageFaultExceptionsThrown");
        recordStats.remove("accessesNotInMemory");
        recordStats.remove("pageFaultExceptionsThrown");

        JSONObject recordStatsTotal = new JSONObject();
        recordStatsTotal.put("accessesNotInMemory", accessNotInMemory);
        recordStatsTotal.put("pageFaultExceptionsThrown", pageFaultExceptionsThrown);
        jsonObj.put("totalRecordStats", recordStatsTotal);
        jsonObj.put("recordStats", recordStats);
        jsonObj.put("ok", ok);
    }//from  w  w w  .  j a  va 2  s . c  o  m

    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");

    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");

    Writer writer = response.getWriter();
    writer.write(jsonObj.toString());

    writer.flush();
}

From source file:com.qcadoo.view.internal.JsonHttpMessageConverter.java

@Override
protected void writeInternal(final JSONObject json, final HttpOutputMessage outputMessage) throws IOException {
    Writer writer = null;

    try {/*  www. j a va  2s .  c om*/
        writer = new OutputStreamWriter(outputMessage.getBody(), CHARSET);
        writer.write(json.toString());
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }
}