Example usage for java.io OutputStream flush

List of usage examples for java.io OutputStream flush

Introduction

In this page you can find the example usage for java.io OutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:net.yacy.cora.protocol.ByteArrayBody.java

@Override
public void writeTo(OutputStream outputStream) throws IOException {
    outputStream.write(this.bytes);
    outputStream.flush();
}

From source file:com.zuoxiaolong.niubi.job.test.http.DownloadFileController.java

@RequestMapping("/download/test.txt")
public void downloadTxt(HttpServletResponse response) throws IOException {
    String fileName = "test.txt";
    response.setContentType("text/plain");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    OutputStream outputStream = response.getOutputStream();
    outputStream.write("hello".getBytes());
    outputStream.flush();
    outputStream.close();//from   w w w .  j a  v  a  2 s.c  om
}

From source file:com.zuoxiaolong.niubi.job.test.http.DownloadFileController.java

@RequestMapping("/download/test.jar")
public void downloadJar(HttpServletResponse response) throws IOException {
    String fileName = "test.jar";
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    OutputStream outputStream = response.getOutputStream();
    outputStream.write("hello".getBytes());
    outputStream.flush();
    outputStream.close();/* w  ww.  jav  a  2s. c om*/
}

From source file:net.di2e.ecdr.source.rest.TrustedServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream os = response.getOutputStream();
    IOUtils.copy(new StringReader("Trust this response"), os);
    os.flush();

}

From source file:de.iew.imageupload.actions.UploadImageAction.java

public void actionPerformed(ActionEvent ev) {
    try {// ww w .  j a  v  a  2s. com
        Socket socket = new Socket("squeeze", 8124);

        FileInputStream fin = new FileInputStream(this.fileToUpload);
        OutputStream out = socket.getOutputStream();

        IOUtils.copy(fin, out);

        out.flush();
        fin.close();
        out.close();

        socket.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.springsource.html5expense.controller.FileAttachmentController.java

@RequestMapping(value = "/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String attachmentId = request.getParameter("attachmentId");
    Attachment attachment = this.attachmentService.getAttachment(new Long(attachmentId));
    response.setContentType(attachment.getContentType());
    response.setHeader("Content-Disposition", "attachment; filename=\"" + attachment.getFileName() + "\"");
    response.setHeader("cache-control", "must-revalidate");
    OutputStream out = response.getOutputStream();
    out.write(attachment.getContent());// w  w w .j a va2 s.c  o m
    out.flush();

}

From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java

private void responseImage(HttpServletResponse response, byte[] imageBytes) throws IOException {
    OutputStream stream = response.getOutputStream();
    stream.write(imageBytes);//  w  w  w  .  j  a  v  a 2s . co m
    stream.flush();
    stream.close();
}

From source file:org.apache.sshd.SpringConfigTest.java

@Test
public void testSpringConfig() throws Exception {
    int port = ((SshServer) context.getBean("sshServer")).getPort();

    JSchLogger.init();// www.  j  a  v a  2  s .c  o m
    JSch sch = new JSch();
    com.jcraft.jsch.Session s = sch.getSession("smx", "localhost", port);
    s.setUserInfo(new SimpleUserInfo("smx"));
    s.connect();
    Channel c = s.openChannel("shell");
    c.connect();
    OutputStream os = c.getOutputStream();
    os.write("this is my command".getBytes());
    os.flush();
    Thread.sleep(100);
    c.disconnect();
    s.disconnect();
}

From source file:org.fishwife.jrugged.spring.StatusController.java

private void writeOutCurrentStatusInResponseBody(HttpServletResponse resp, Status currentStatus)
        throws IOException {
    resp.setHeader("Content-Type", "text/plain;charset=utf-8");
    String body = currentStatus + "\n";
    byte[] bytes = body.getBytes();
    resp.setHeader("Content-Length", bytes.length + "");
    OutputStream out = resp.getOutputStream();
    out.write(bytes);/*www.  j ava 2 s .c om*/
    out.flush();
    out.close();
}

From source file:org.zht.framework.web.converter.MappingFastjsonHttpMessageConverter.java

@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    //JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.DisableCircularReferenceDetect.getMask();
    String jsonString = JSON.toJSONString(o, features);
    OutputStream out = outputMessage.getBody();
    out.write(jsonString.getBytes(DEFAULT_CHARSET));
    out.flush();
}