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.wondershare.http.server.impl.CallogServlet.java

@Override
protected void doGet(HttpRequest request, HttpResponse response, HttpContext context)
        throws IOException, ServletException {
    Cursor cursor = mContext.getContentResolver().query(callogUri, SysConst.CALLOG_PROJECTION, null, null,
            null);/*from  w w w. ja  v a 2s.  co  m*/
    final String html = Utils.spellCallogToHTML(cursor);
    HttpEntity entity = new EntityTemplate(new ContentProducer() {
        @Override
        public void writeTo(OutputStream outstream) throws IOException {
            OutputStreamWriter out = new OutputStreamWriter(outstream);
            out.write(html);
            out.flush();
        }
    });
    ((EntityTemplate) entity).setContentType("text/html");
    response.setEntity(entity);
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamingTemplate.java

private ClientHttpResponse executeRequest(HttpMethod method, String url, MultiValueMap<String, String> body)
        throws IOException {
    ClientHttpRequestFactory requestFactory = this.getRestTemplate().getRequestFactory();
    ClientHttpRequest request = requestFactory.createRequest(URI.create(url), method);
    OutputStreamWriter writer = new OutputStreamWriter(request.getBody());
    writer.write(createFormUrlEncodedBodyString(body));
    writer.flush();//from  w  w w .j a  va 2  s.c  om
    return request.execute();
}

From source file:org.wso2.carbon.automation.extensions.servers.httpserver.TestRequestHandler.java

private EntityTemplate createEntity() {
    return new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
            writer.write(payload);
            writer.flush();//from   w ww .j a v  a 2  s.  com
        }
    });
}

From source file:com.naver.wysohn2002.mythicmobcreator.util.Utf8YamlConfiguration.java

@Override
public void save(File file) throws IOException {
    Validate.notNull(file, "File cannot be null");

    Files.createParentDirs(file);

    String data = saveToString();

    FileOutputStream stream = new FileOutputStream(file);
    OutputStreamWriter writer = new OutputStreamWriter(stream, UTF8_CHARSET);

    try {//from ww  w .  j  a  v a 2  s.c  om
        writer.write(data);
    } finally {
        writer.close();
    }
}

From source file:griffon.plugins.preferences.persistors.JsonPreferencesPersistor.java

@Override
protected void write(@Nonnull Map<String, Object> map, @Nonnull OutputStream outputStream) throws IOException {
    JSONObject json = new JSONObject(map);
    OutputStreamWriter writer = new OutputStreamWriter(outputStream);
    writer.write(json.toString(4));
    writer.flush();//from  ww  w.  java  2 s.  c  o m
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

public static void writeFileText(final File file, final String text) throws SSErr {

    OutputStreamWriter fileOut = null;

    try {//  w  w w .j  a  v a2s . com
        //    final byte[]        bytes      = text.getBytes();

        fileOut = new OutputStreamWriter(openOrCreateFileWithPathForWrite(file.getAbsolutePath()),
                Charset.forName(SSEncodingU.utf8.toString()));

        fileOut.write(text);
        //      fileOut.write (bytes, 0, bytes.length);

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (fileOut != null) {

            try {
                fileOut.close();
            } catch (IOException error) {
                SSLogU.err(error);
            }
        }
    }
}

From source file:me.cybermaxke.mobiletools.utils.converter.AlphaYamlConfiguration.java

@Override
public void save(File file) throws IOException {
    Validate.notNull(file, "File cannot be null");

    Files.createParentDirs(file);

    String data = this.saveToString();

    FileOutputStream stream = new FileOutputStream(file);
    OutputStreamWriter writer = new OutputStreamWriter(stream, Charset.forName("UTF-8"));

    try {/* w ww . j a v  a  2s  .  c  o m*/
        writer.write(data);
    } finally {
        writer.close();
    }
}

From source file:de.undercouch.gradle.tasks.download.CompressionTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler compressionHandler = new ContextHandler("/" + COMPRESSED) {
        @Override//ww  w . ja  v a 2  s.co m
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            String acceptEncoding = request.getHeader("Accept-Encoding");
            boolean acceptGzip = "gzip".equals(acceptEncoding);

            response.setStatus(200);
            OutputStream os = response.getOutputStream();
            if (acceptGzip) {
                response.setHeader("Content-Encoding", "gzip");
                GZIPOutputStream gos = new GZIPOutputStream(os);
                OutputStreamWriter osw = new OutputStreamWriter(gos);
                osw.write("Compressed");
                osw.close();
                gos.flush();
                gos.close();
            } else {
                OutputStreamWriter osw = new OutputStreamWriter(os);
                osw.write("Uncompressed");
                osw.close();
            }
            os.close();
        }
    };
    return new Handler[] { compressionHandler };
}

From source file:com.writewreckedsoftware.ullr.networking.UpdateMarker.java

@Override
protected String doInBackground(String... arg0) {
    String json = arg0[0];/*from  ww  w  . j  a  v a 2 s. c  om*/
    JSONObject obj = null;
    String id = "";
    try {
        obj = new JSONObject(json);
        id = obj.getString("_id");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    URL url = null;
    String resultText = "";
    try {
        url = new URL("http://ullr.herokuapp.com/markers/" + id);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("PUT");
        connection.setRequestProperty("Content-Type", "application/json");
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
        out.write(json);
        out.close();
        InputStream response = connection.getInputStream();
        resultText = NetworkHelpers.getInstance(null).convertStreamToString(response);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    JSONObject result = null;
    try {
        result = new JSONObject(resultText);
        result.put("_id", id);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return result.toString();
}

From source file:com.jyzn.wifi.validate.platforminterface.SmsInterfaceImpl.java

@Override
public Map HttpSendSms(String postUrl, String postData) {
    String result = "";
    Map resultMap = Maps.newHashMap();
    try {/*from   ww  w . java 2 s .  com*/
        //??POST
        URL url = new URL(postUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setUseCaches(false);
        conn.setDoOutput(true);
        conn.setRequestProperty("Content-Length", "" + postData.length());

        try {
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            out.write(postData);
            out.flush();//?
        } catch (IOException e) {
        }

        //???
        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            System.out.println("connect failed!");
            resultMap.put("status", "fail");
            //return "fail";
        }

        //??
        String line;
        try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
            while ((line = in.readLine()) != null) {
                result += line + "\n";
            }
        }
        resultMap.put("status", "sucess");
        resultMap.put("result", result);
    } catch (IOException e) {
        e.printStackTrace(System.out);
    }
    return resultMap;
}