List of usage examples for java.io OutputStreamWriter flush
public void flush() throws IOException
From source file:at.tugraz.ist.akm.webservice.requestprocessor.HttpResponseDataAppender.java
public void appendHttpResponseData(HttpResponse httpResponse, final String contentType, final String data) { httpResponse.setEntity(new EntityTemplate(new ContentProducer() { @Override/* w w w. ja v a2s.c om*/ public void writeTo(OutputStream outstream) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(outstream, mDefaultEncoding); writer.write(data); writer.flush(); writer.close(); } })); httpResponse.setHeader(WebServerConstants.HTTP.KEY_CONTENT_TYPE, contentType); }
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);/*www .j a va 2s . c o 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:io.mingle.v1.Connection.java
public Response run(String comprehension) { String expr = "{ \"query\": \"" + comprehension + "\", \"limit\": 10000 }"; try {/*w ww. j a v a 2 s . c o m*/ HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); conn.connect(); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(expr, 0, expr.length()); out.flush(); out.close(); InputStream in = conn.getInputStream(); ByteArrayOutputStream buf = new ByteArrayOutputStream(); byte[] chunk = new byte[4096]; int read = 0; while ((read = in.read(chunk)) > 0) { buf.write(chunk, 0, read); } in.close(); String str = buf.toString(); System.out.println("GOT JSON: " + str); return new Response(JSONValue.parse(str)); } catch (Exception e) { System.err.printf("failed to execute: %s\n", expr); e.printStackTrace(); } return null; }
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);//from w w w . jav a2s. co m writer.flush(); } }); }
From source file:com.wondershare.http.server.impl.HomePageServlet.java
@Override protected void doGet(HttpRequest request, HttpResponse response, HttpContext context) throws IOException, ServletException { HttpEntity entity = new EntityTemplate(new ContentProducer() { @Override/*from ww w . j a v a 2 s . c o m*/ public void writeTo(OutputStream outstream) throws IOException { OutputStreamWriter out = new OutputStreamWriter(outstream); out.write(Utils.openHTMLString(mContext, R.raw.home)); out.flush(); } }); ((EntityTemplate) entity).setContentType("text/html"); response.setEntity(entity); }
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));//from w ww. j ava 2s . c om writer.flush(); }
From source file:com.packpublishing.asynchronousandroid.chapter7.SyncTask.java
private void uploadJsonToServer(HttpURLConnection urlConn, String body) throws Exception { OutputStreamWriter writer = new OutputStreamWriter(urlConn.getOutputStream()); writer.write(body);/*from www . j av a 2 s . c o m*/ writer.flush(); writer.close(); int resultCode = urlConn.getResponseCode(); if (resultCode != HttpURLConnection.HTTP_OK) { throw new Exception("Failed to sync with server :" + resultCode); } }
From source file:com.msopentech.odatajclient.testservice.utils.XmlElement.java
public InputStream toStream() throws Exception { InputStream res;//from w w w.j av a2 s. c o m try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final OutputStreamWriter osw = new OutputStreamWriter(bos); getStart().writeAsEncodedUnicode(osw); osw.flush(); IOUtils.copy(getContent(), bos); getEnd().writeAsEncodedUnicode(osw); osw.flush(); osw.close(); res = new ByteArrayInputStream(bos.toByteArray()); } catch (Exception e) { LOG.error("Error serializing elemnt", e); res = null; } return res; }
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 {//w ww. j av a2 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; }
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(); return request.execute(); }