Example usage for java.io OutputStreamWriter write

List of usage examples for java.io OutputStreamWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:com.hangum.tadpole.importexport.core.dialogs.CsvToRDBImportDialog.java

private void saveLog() {
    try {//from w w  w.  ja  v  a 2s . co m
        if ("".equals(textSQL.getText())) { //$NON-NLS-1$
            MessageDialog.openWarning(null, Messages.get().Warning,
                    Messages.get().SQLToDBImportDialog_LogEmpty);
            return;
        }
        String filename = PublicTadpoleDefine.TEMP_DIR + userDB.getDisplay_name() + "_SQLImportResult.log"; //$NON-NLS-1$

        FileOutputStream fos = new FileOutputStream(filename);
        OutputStreamWriter bw = new OutputStreamWriter(fos, "UTF-8"); //$NON-NLS-1$

        bw.write(textSQL.getText());
        bw.close();

        String strImportResultLogContent = FileUtils.readFileToString(new File(filename));

        downloadExtFile(userDB.getDisplay_name() + "_SQLImportResult.log", strImportResultLogContent);//sbExportData.toString()); //$NON-NLS-1$
    } catch (Exception ee) {
        logger.error("log writer", ee); //$NON-NLS-1$
    }
}

From source file:edu.utsa.sifter.IndexResource.java

void writeRecord(final Result doc, final Bookmark mark, final OutputStreamWriter writer) throws IOException {
    writer.write(nullCheck(doc.ID));
    writer.write(",");
    writer.write(Double.toString(doc.Score));
    writer.write(",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Name)));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Path)));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Extension)));
    writer.write("\",");
    writer.write(Long.toString(doc.Size));
    writer.write(",");
    writer.write(Long.toString(doc.Modified));
    writer.write(",");
    writer.write(Long.toString(doc.Accessed));
    writer.write(",");
    writer.write(Long.toString(doc.Created));
    writer.write(",");
    writer.write(nullCheck(doc.Cell));//from  w  w w  . ja v  a  2  s.c  om
    writer.write(",");
    writer.write(Double.toString(doc.CellDistance));
    writer.write(",");
    writer.write(mark == null ? "0" : Long.toString(mark.Created));
    writer.write(",");
    writer.write(mark == null ? "" : StringEscapeUtils.escapeCsv(nullCheck(mark.Comment)));
    writer.write("\n");
}

From source file:com.hqme.cm.cache.StreamingServer.java

public void run() {
    if (UntenCacheService.sIsDebugMode) {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
        Thread.currentThread().setName(getClass().getName());
    }/*  ww w.j  ava 2  s .  c  om*/

    isStopping = false;
    serverSocket = null;
    serverPortPrefs = new File(UntenCacheService.sPluginContext.getFilesDir(), tag_PlaybackPortNumber);
    try {
        String text = new BufferedReader(new InputStreamReader(new FileInputStream(serverPortPrefs), "UTF16"),
                1 << 10).readLine();
        serverPortNumber = Integer.valueOf(text.trim());
    } catch (Throwable ignore) {
        serverPortNumber = 0;
    }

    int retries = 2;
    while (retries-- > 0) {
        try {
            serverSocket = new ServerSocket(serverPortNumber);
            if (serverPortNumber == 0) {
                serverPortNumber = serverSocket.getLocalPort();
                try {
                    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(serverPortPrefs),
                            "UTF16");
                    writer.write(serverPortNumber + "\r\n");
                    writer.flush();
                    writer.close();
                } catch (Throwable ignore) {
                }
            }
            clientBox = new ClientBox[MAX_CLIENTS];
            retries = 0;

            UntenCacheService.debugLog(sTag, "run: Streaming Media Server is now active on TCP port # %d",
                    serverPortNumber);
            handleRequests();
        } catch (IOException fault) {
            fault.printStackTrace();
            try {
                serverPortPrefs.delete();
            } catch (Throwable ignore) {
            }
        }
    }
}

From source file:com.syncedsynapse.kore2.jsonrpc.HostConnection.java

/**
 * Send an HTTP POST request/*from w w  w  .j  a va 2 s . co m*/
 * @param connection Open connection
 * @param request Request to send
 * @throws ApiException
 */
private void sendHttpRequest(HttpURLConnection connection, String request) throws ApiException {
    try {
        LogUtils.LOGD(TAG, "Sending request via HTTP: " + request);
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
        out.write(request);
        out.flush();
        out.close();
    } catch (IOException e) {
        LogUtils.LOGW(TAG, "Failed to send HTTP request.", e);
        throw new ApiException(ApiException.IO_EXCEPTION_WHILE_SENDING_REQUEST, e);
    }

}

From source file:UploadTest.java

@Test
public void test_with_javaLib() {
    httpCon.disconnect();// w w  w .j a v  a 2  s. com
    try {
        // readStream(httpCon.getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
    httpCon.setRequestProperty("Content-Type", "application/json");
    httpCon.setRequestProperty("Accept", "application/json");
    httpCon.setDoOutput(true);
    try {
        httpCon.setRequestMethod("PUT");
    } catch (ProtocolException e) {
        e.printStackTrace();
    }
    try {
        httpCon.connect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    String content = "{\"contentType\":\"monograph\",\"accessScheme\":\"public\",\"publishScheme\":\"public\"}";
    System.out.println(content);
    OutputStreamWriter out;
    try {
        out = new OutputStreamWriter(httpCon.getOutputStream());
        out.write(content);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        System.out.println(httpCon.getResponseCode());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.kjt.service.common.SoafwTesterMojo.java

private void write(String dest, String template, String tpl) throws MojoExecutionException {
    // FileWriter fw = null;
    OutputStreamWriter osw = null;
    try {//from  w  w  w. ja v a  2 s .c om
        new File(dest).mkdirs();
        osw = new OutputStreamWriter(new FileOutputStream(dest + File.separator + template), "UTF-8");
        // fw = new FileWriter(dest + File.separator + template);
        osw.write(tpl);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    } finally {
        try {
            if (osw != null) {
                osw.close();
            }
        } catch (IOException e) {
        }
    }
}

From source file:it.infn.ct.ToscaIDCInterface.java

/**
 * Submit template to the orchestrator a template.
 * @return TOSCA UUID//  w  w w . j av a  2  s  .c  om
 */
public final String submitOrchestrator() {

    StringBuilder orchestratorResult = new StringBuilder("");
    StringBuilder postData = new StringBuilder();
    String toscParametersValues = "";
    String toscaParametersJson = "";
    String tUUID = "";
    String[] toscaParams = toscaParameters.split("&");
    String tParams = "";
    for (int i = 0; i < toscaParams.length; i++) {
        String[] paramArgs = toscaParams[i].split("=");
        if (paramArgs[0].trim().equals("params")) {
            toscaParametersJson = toscaCommand.getActionInfo() + FS + paramArgs[1].trim();
            LOG.debug("Loading params json file: '" + toscaParametersJson + "'");
            try {
                String paramsJson = new String(Files.readAllBytes(Paths.get(toscaParametersJson)));
                LOG.debug("params JSON: '" + paramsJson + "'");
                toscParametersValues = getDocumentValue(paramsJson, "parameters");
                LOG.debug("extracted parameters: '" + tParams + "'");
            } catch (IOException ex) {
                LOG.error("Parameters json file '" + toscaParametersJson + "' is not readable");
                LOG.error(ex);
            } catch (ParseException ex) {
                LOG.error("Parameters json file '" + toscaParametersJson + "' is not parseable");
                LOG.error(ex);
            }
            LOG.debug("Parameters json file '" + toscaParametersJson + "' successfully parsed");
            break;
        }
    }
    if (toscParametersValues.length() > 0) {
        tParams = "\"parameters\": " + toscParametersValues + ", ";
    }
    postData.append("{ " + tParams + "\"template\": \"");
    String toscaTemplateContent = "";
    LOG.debug("Escaping toscaTemplate file '" + toscaTemplate + "'");
    try {
        toscaTemplateContent = new String(Files.readAllBytes(Paths.get(toscaTemplate))).replace("\n", "\\n");
    } catch (IOException ex) {
        LOG.error("Template '" + toscaTemplate + "'is not readable");
        LOG.error(ex);
    }
    postData.append(toscaTemplateContent);
    postData.append("\" }");
    LOG.debug("JSON Data (begin):\n" + postData + "\nJSON Data (end)");

    HttpURLConnection conn;
    String orchestratorDoc = "";
    try {
        conn = (HttpURLConnection) toscaEndPoint.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + toscaToken);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("charset", "utf-8");
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(postData.toString());
        wr.flush();
        wr.close();
        LOG.debug("Orchestrator status code: " + conn.getResponseCode());
        LOG.debug("Orchestrator status message: " + conn.getResponseMessage());
        if (conn.getResponseCode() == HTTP_201) {
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            orchestratorResult = new StringBuilder();
            String ln;
            while ((ln = br.readLine()) != null) {
                orchestratorResult.append(ln);
            }
            LOG.debug("Orchestrator result: " + orchestratorResult);
            orchestratorDoc = orchestratorResult.toString();
            tUUID = getDocumentValue(orchestratorDoc, "uuid");
            LOG.debug("Created resource has UUID: '" + tUUID + "'");
        } else {
            LOG.warn("Orchestrator return code is: " + conn.getResponseCode());
        }
    } catch (IOException ex) {
        LOG.error("Connection error with the service at " + toscaEndPoint.toString());
        LOG.error(ex);
    } catch (ParseException ex) {
        LOG.error("Error parsing JSON:" + orchestratorDoc);
        LOG.error(ex);
    }
    return tUUID;
}

From source file:edu.utsa.sifter.IndexResource.java

void writeDocRecordFeatures(final Result doc, final Bookmark mark, final OutputStreamWriter writer,
        final double feat) throws IOException {
    writer.write(nullCheck(doc.ID));
    writer.write(",");
    writer.write(Double.toString(doc.Score));
    writer.write(",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Name)));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Path)));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(doc.Extension)));
    writer.write("\",");
    writer.write(Long.toString(doc.Size));
    writer.write(",");
    writer.write(Long.toString(doc.Modified));
    writer.write(",");
    writer.write(Long.toString(doc.Accessed));
    writer.write(",");
    writer.write(Long.toString(doc.Created));
    writer.write(",");
    writer.write(nullCheck(doc.Cell));/*w ww  .  jav  a  2 s.  c  o  m*/
    writer.write(",");
    writer.write(Double.toString(doc.CellDistance));
    writer.write(",");
    writer.write(mark == null ? "0" : Long.toString(mark.Created));
    writer.write(",");
    writer.write(mark == null ? "" : StringEscapeUtils.escapeCsv(nullCheck(mark.Comment)));
    writer.write(",");
    writer.write(Double.toString(feat));

    writer.write("\n");
}

From source file:edu.utsa.sifter.IndexResource.java

void writeHitRecord(final SearchHit hit, final Bookmark mark, final OutputStreamWriter writer)
        throws IOException, InterruptedException {
    writer.write(nullCheck(hit.ID()));
    writer.write(",");
    writer.write(Double.toString(hit.Score));
    writer.write(",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(hit.Name())));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(hit.Path())));
    writer.write("\",\"");
    writer.write(nullCheck(StringEscapeUtils.escapeCsv(hit.Extension())));
    writer.write("\",");
    writer.write(Long.toString(hit.Size()));
    writer.write(",");
    writer.write(Long.toString(hit.Modified()));
    writer.write(",");
    writer.write(Long.toString(hit.Accessed()));
    writer.write(",");
    writer.write(Long.toString(hit.Created()));
    writer.write(",");
    writer.write(nullCheck(hit.Cell()));
    writer.write(",");
    writer.write(Double.toString(hit.CellDistance()));
    writer.write(",");
    writer.write(Long.toString(hit.Start));
    writer.write(",");
    writer.write(Long.toString(hit.End));
    writer.write(",");
    writer.write(nullCheck(StringEscapeUtils.escapeCsv(hit.Passage.replace('\n', ' ').replace('\r', ' '))));
    writer.write(",");
    writer.write(mark == null ? "0" : Long.toString(mark.Created));
    writer.write(",");
    writer.write(mark == null ? "" : StringEscapeUtils.escapeCsv(nullCheck(mark.Comment)));
    writer.write("\n");
}

From source file:edu.utsa.sifter.IndexResource.java

void writeHitRecordFeatures(final SearchHit hit, final Bookmark mark, final OutputStreamWriter writer)
        throws IOException, InterruptedException {
    writer.write(nullCheck(hit.ID()));
    writer.write(",");
    writer.write(Double.toString(hit.Score));
    writer.write(",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(hit.Name())));
    writer.write("\",\"");
    writer.write(StringEscapeUtils.escapeCsv(nullCheck(hit.Path())));
    writer.write("\",\"");
    writer.write(nullCheck(StringEscapeUtils.escapeCsv(hit.Extension())));
    writer.write("\",");
    writer.write(Long.toString(hit.Size()));
    writer.write(",");
    writer.write(Long.toString(hit.Modified()));
    writer.write(",");
    writer.write(Long.toString(hit.Accessed()));
    writer.write(",");
    writer.write(Long.toString(hit.Created()));
    writer.write(",");
    writer.write(nullCheck(hit.Cell()));
    writer.write(",");
    writer.write(Double.toString(hit.CellDistance()));
    writer.write(",");
    writer.write(Long.toString(hit.Start));
    writer.write(",");
    writer.write(Long.toString(hit.End));
    writer.write(",");
    writer.write(nullCheck(StringEscapeUtils.escapeCsv(hit.Passage.replace('\n', ' ').replace('\r', ' '))));
    writer.write(",");
    writer.write(mark == null ? "0" : Long.toString(mark.Created));
    writer.write(",");
    writer.write(mark == null ? "" : StringEscapeUtils.escapeCsv(nullCheck(mark.Comment)));
    writer.write("\n");
}