List of usage examples for java.io OutputStream flush
public void flush() throws IOException
From source file:com.adaptris.core.stubs.MockEncoder.java
public void writeMessage(AdaptrisMessage msg, Object target) throws CoreException { try {/*from w ww .j ava2 s . c om*/ if (!(target instanceof OutputStream)) { throw new IllegalArgumentException("MockEncoder can only encode to an OutputStream"); } OutputStream encodedOutput = (OutputStream) target; encodedOutput.write(msg.getPayload()); encodedOutput.flush(); } catch (Exception e) { throw new CoreException("Could not encode the AdaptrisMessage object", e); } }
From source file:org.sakaiproject.oaai.controller.FileDownloadController.java
@RequestMapping(method = RequestMethod.POST) public void doDownload(HttpServletRequest request, HttpServletResponse response) { String datedDirectory = request.getParameter("directory"); String action = request.getParameter("action"); String fileName = action + ".csv"; String csvData = data.getCsvData(datedDirectory, fileName); response.setContentType(Constants.MIME_TYPE_CSV); response.setHeader("Content-Disposition", "attachment; filename='" + fileName + "'"); try {//from w ww. j av a2s. c om OutputStream outputStream = response.getOutputStream(); outputStream.write(csvData.getBytes()); outputStream.flush(); outputStream.close(); } catch (Exception e) { log.error("Error sending CSV file to browser: " + e, e); } }
From source file:com.zoonies.cinc.resources.PojoMessageBodyWriter.java
@Override public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { mapper.writeValue(entityStream, t);//w ww . j a v a 2 s .c om entityStream.flush(); }
From source file:org.envirocar.server.rest.encoding.json.AbstractJSONMessageBodyWriter.java
@Override public void writeTo(T t, Class<?> c, Type gt, Annotation[] a, MediaType mt, MultivaluedMap<String, Object> h, OutputStream out) throws IOException, WebApplicationException { writer.writeValue(out, encodeJSON(t, mt)); out.flush(); }
From source file:com.utest.webservice.auth.BasicAuthAuthorizationInterceptor.java
private void close(final Message outMessage) throws IOException { final OutputStream os = outMessage.getContent(OutputStream.class); os.flush(); os.close();//w w w. j a va2 s . com }
From source file:com.sunney.eweb.config.MappingFastjson2HttpMessageConverter.java
@Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { String jsonString = JSON.toJSONString(o, serializerFeature); OutputStream out = outputMessage.getBody(); out.write(jsonString.getBytes(DEFAULT_CHARSET)); out.flush(); }
From source file:com.mingsoft.weixin.util.UploadDownUtils.java
/** * ? ? /*from w ww .ja v a2 s.co m*/ * @param access_token ?? * @param msgType image?voice?videothumb * @param localFile * @return */ @Deprecated public static String uploadMedia(String access_token, String msgType, String localFile) { String media_id = null; String url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + access_token + "&type=" + msgType; String local_url = localFile; try { File file = new File(local_url); if (!file.exists() || !file.isFile()) { log.error("==" + local_url); return null; } URL urlObj = new URL(url); HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); con.setRequestMethod("POST"); // Post????get? con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); // post?? // ? con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Charset", "UTF-8"); // String BOUNDARY = "----------" + System.currentTimeMillis(); con.setRequestProperty("content-type", "multipart/form-data; boundary=" + BOUNDARY); // con.setRequestProperty("Content-Type", // "multipart/mixed; boundary=" + BOUNDARY); // con.setRequestProperty("content-type", "text/html"); // ? // StringBuilder sb = new StringBuilder(); sb.append("--"); // ////////? sb.append(BOUNDARY); sb.append("\r\n"); sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n"); sb.append("Content-Type:application/octet-stream\r\n\r\n"); byte[] head = sb.toString().getBytes("utf-8"); // ? OutputStream out = new DataOutputStream(con.getOutputStream()); out.write(head); // DataInputStream in = new DataInputStream(new FileInputStream(file)); int bytes = 0; byte[] bufferOut = new byte[1024]; while ((bytes = in.read(bufferOut)) != -1) { out.write(bufferOut, 0, bytes); } in.close(); // byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// ?? out.write(foot); out.flush(); out.close(); /** * ????,????? */ // con.getResponseCode(); try { // BufferedReader???URL? StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); String line = null; while ((line = reader.readLine()) != null) { // System.out.println(line); buffer.append(line); } String respStr = buffer.toString(); log.debug("==respStr==" + respStr); try { JSONObject dataJson = JSONObject.parseObject(respStr); media_id = dataJson.getString("media_id"); } catch (Exception e) { log.error("==respStr==" + respStr, e); try { JSONObject dataJson = JSONObject.parseObject(respStr); return dataJson.getString("errcode"); } catch (Exception e1) { } } } catch (Exception e) { log.error("??POST?" + e); } } catch (Exception e) { log.error("?!=" + local_url); log.error("?!", e); } finally { } return media_id; }
From source file:costumetrade.common.verify.CapchaController.java
@EscapeLogin @RequestMapping("/capcha/get") public void get(String businessKey, HttpServletResponse response) throws IOException { if (StringUtils.isBlank(businessKey)) { throw new IllegalArgumentException("key?"); }/*from w w w . ja v a 2 s.co m*/ response.setContentType("image/png"); response.setDateHeader("exprise", -1); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); Pair<String, BufferedImage> codeImage = ImageVerification.create(); captchaService.save(businessKey, codeImage.first()); OutputStream outputStream = response.getOutputStream(); ImageIO.write(codeImage.second(), "png", outputStream); outputStream.flush(); }
From source file:de.onyxbits.raccoon.net.ResourceHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("application/octet-stream"); response.setStatus(HttpServletResponse.SC_OK); if (target.toLowerCase().endsWith("png")) { response.setContentType("image/png"); }//from ww w.j a va 2 s . c o m if (target.toLowerCase().endsWith("css")) { response.setContentType("text/css"); } // Prevent path traversal -> all resources must be in /web, no sub // directories. String tmp = target.substring(target.lastIndexOf('/'), target.length()); InputStream in = getClass().getResourceAsStream("/web" + tmp); OutputStream out = response.getOutputStream(); IOUtils.copy(in, out); in.close(); out.flush(); out.close(); baseRequest.setHandled(true); }
From source file:com.bt.download.android.core.HttpFetcher.java
private static void writeEntity(final HttpEntity entity, OutputStream out, HttpFetcherListener listener) throws IOException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); }//from ww w. j a va2 s . com InputStream in = entity.getContent(); if (in == null) { return; } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } try { byte[] data = new byte[4096]; int n; while ((n = in.read(data)) != -1) { if (listener != null) { listener.onData(data, n); } out.write(data, 0, n); out.flush(); } } finally { in.close(); } }