List of usage examples for java.io OutputStream flush
public void flush() throws IOException
From source file:gridool.communication.transport.tcp.GridOioSharedClient.java
private synchronized void syncWrite(final Socket socket, final byte[] b) throws IOException { OutputStream sockout = socket.getOutputStream(); sockout.write(b);// ww w . ja v a2s .c o m sockout.flush(); }
From source file:org.jasig.portlet.cms.controller.DownloadPostAttachmentController.java
@RequestMapping protected void handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final HttpSession session = request.getSession(); final Attachment attachment = (Attachment) session.getAttribute("attachment"); logDebug("Attempting to download attachment: " + attachment); response.setContentType("application/x-download"); logDebug("Set content type to: " + response.getContentType()); final String encoding = response.getCharacterEncoding(); logDebug("Encoded file name based on: " + encoding); final String fileName = URLEncoder.encode(attachment.getFileName(), encoding); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); logDebug("Downloading file: " + fileName); final OutputStream out = response.getOutputStream(); out.write(attachment.getContents()); out.flush(); logDebug("Clearing session attribute"); session.setAttribute("attachment", null); }
From source file:org.sakaiproject.lap.controller.FileDownloadController.java
@RequestMapping(method = RequestMethod.POST) public void doDownload(HttpServletRequest request, HttpServletResponse response) { String datedDirectory = request.getParameter("extraction-date"); String action = request.getParameter("action"); String fileName = action + ".csv"; String csvData = data.getCsvDataString(datedDirectory, fileName); response.setContentType(Constants.MIME_TYPE_CSV); response.setHeader("Content-Disposition", "attachment; filename='" + fileName + "'"); try {/*w w w . ja v a 2s. com*/ 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.linecorp.armeria.internal.ConnectionLimitingHandlerIntegrationTest.java
private Socket newSocketAndTest() throws IOException { Socket socket = new Socket(LOOPBACK, server.httpPort()); // Test this socket is opened or not. OutputStream os = socket.getOutputStream(); os.write("GET / HTTP/1.1\r\n\r\n".getBytes()); os.flush(); // Read the next byte and ignore it. socket.getInputStream().read();// w ww . j a va 2s .c o m return socket; }
From source file:com.maydesk.base.util.ByteArrayImageReference.java
@Override public void render(OutputStream out) throws IOException { try {/* ww w .ja v a2 s.c o m*/ IOUtils.copy(new ByteArrayInputStream(data), out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.gmail.ferusgrim.util.UuidGrabber.java
public Map<String, UUID> call() throws Exception { JSONParser jsonParser = new JSONParser(); Map<String, UUID> responseMap = new HashMap<String, UUID>(); URL url = new URL("https://api.mojang.com/profiles/minecraft"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setUseCaches(false);// w w w. j a v a2 s .co m connection.setDoInput(true); connection.setDoOutput(true); String body = JSONArray.toJSONString(this.namesToLookup); OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); stream.flush(); stream.close(); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = Grab.uuidFromResult(id); responseMap.put(name, uuid); } return responseMap; }
From source file:io.scigraph.services.jersey.writers.BbopJsGraphWriter.java
@Override public void writeTo(Graph data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException { BbopGraph bbopGraph = graphUtil.convertGraph(data); MAPPER.writeValue(out, bbopGraph);//from w w w . j a va 2s . c o m out.flush(); }
From source file:gridool.communication.transport.tcp.GridOioClient.java
public void sendMessage(SocketAddress sockAddr, GridCommunicationMessage msg) throws GridException { final Socket socket; try {//from w ww . j ava 2s . c o m socket = SocketUtils.openSocket(sockAddr, 0, 2000L, 3); } catch (IOException e) { LOG.error("failed to connect: " + sockAddr, e); throw new GridException(e); } final byte[] b = GridUtils.toBytes(msg); // TODO sendfile support if (LOG.isDebugEnabled()) { LOG.debug("Sending a message [" + msg.getMessageId() + " (" + b.length + " bytes)] to a node [" + sockAddr + "] using a socket [" + socket + ']'); } try { OutputStream sockout = socket.getOutputStream(); sockout.write(b); sockout.flush(); NetUtils.shutdownOutputQuietly(socket); // terminate socket output (send FIN) } catch (IOException ioe) { final String errmsg = "Failed to send a GridCommunicationMessage [" + msg + "] to host [" + sockAddr + ']'; LOG.error(errmsg, ioe); throw new GridException(errmsg, ioe); } catch (Throwable e) { LOG.fatal(PrintUtils.prettyPrintStackTrace(e, -1)); throw new GridException("Unexpected exception was caused", e); } finally { NetUtils.closeQuietly(socket); } }
From source file:yadarts.server.json.AbstractJSONWriter.java
@Override public void writeTo(T t, Class<?> c, Type gt, Annotation[] a, MediaType mt, MultivaluedMap<String, Object> h, OutputStream os) throws IOException, WebApplicationException { objectWriter.writeValue(os, encode(t, mt)); os.flush(); }
From source file:com.cognifide.aet.rest.ArtifactServlet.java
@Override protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse resp) throws IOException { String id = req.getParameter(Helper.ID_PARAM); resp.setCharacterEncoding("UTF-8"); Artifact artifact = artifactsDAO.getArtifact(dbKey, id); if (artifact != null) { resp.setContentType(artifact.getContentType()); resp.setHeader("Cache-Control", "public, max-age=31536000"); OutputStream output = resp.getOutputStream(); IOUtils.copy(artifact.getArtifactStream(), output); output.flush(); } else {//from w ww . j a va 2 s. c om resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST); resp.setContentType("application/json"); resp.getWriter() .write(responseAsJson("Unable to get artifact with id : %s form %s", id, dbKey.toString())); } }