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:com.splunk.shuttl.archiver.bucketlock.SimpleFileLockSharedTest.java

private void signalOtherJvmToFinish() throws IOException {
    OutputStream out = otherJvmLocker.getOutputStreamToClass();
    out.write(DATA);//  www  .j  a va  2 s .c o m
    out.flush();
}

From source file:com.mockey.ui.JsonSchemaLoadSamplesServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final int index = RND.nextInt(SAMPLE_DATA_SIZE);
    final JsonNode ret = SAMPLE_DATA.get(index);

    final OutputStream out = resp.getOutputStream();

    try {/*from  w w w. java  2  s.  co  m*/
        out.write(ret.toString().getBytes(Charset.forName("UTF-8")));
        out.flush();
    } finally {
        Closeables.closeQuietly(out);
    }
}

From source file:com.wso2.raspberrypi.apicalls.HttpClient.java

public HttpResponse doPost(String url, String token, final String payload, String contentType)
        throws IOException {
    HttpUriRequest request = new HttpPost(url);
    addSecurityHeaders(request, token);//from   w  w  w.jav  a  2  s  . c  o  m

    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            outputStream.write(payload.getBytes());
            outputStream.flush();
        }
    });
    ent.setContentType(contentType);
    entityEncReq.setEntity(ent);
    return client.execute(request);
}

From source file:com.wso2.raspberrypi.apicalls.HttpClient.java

public HttpResponse doPut(String url, String token, final String payload, String contentType)
        throws IOException {
    HttpUriRequest request = new HttpPut(url);
    addSecurityHeaders(request, token);/*from w w  w .j  ava  2 s.  c  o  m*/

    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            outputStream.write(payload.getBytes());
            outputStream.flush();
        }
    });
    ent.setContentType(contentType);
    entityEncReq.setEntity(ent);
    return client.execute(request);
}

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

public static void readFileBytes(final OutputStream outStream, final FileInputStream fileIn) throws Exception {

    if (SSObjU.isNull(outStream, fileIn)) {
        throw new Exception("pars not okay");
    }/*from  ww w .  j  av  a  2  s .co  m*/

    final byte[] fileBytes = new byte[SSSocketU.socketTranmissionSize];
    int read;

    try {

        while ((read = fileIn.read(fileBytes)) != -1) {

            if (fileBytes.length == 0 || read <= 0) {

                outStream.write(new byte[0]);
                outStream.flush();
                break;
            }

            outStream.write(fileBytes, 0, read);
            outStream.flush();
        }
    } catch (Exception error) {
        throw error;
    } finally {

        if (outStream != null) {
            outStream.close();
        }

        if (fileIn != null) {
            fileIn.close();
        }
    }
}

From source file:com.bdx.rainbow.spsy.controller.syjg.LicenseController.java

@RequestMapping("/excelOut")
public void companyInfoExcelOut(HttpServletRequest request, HttpServletResponse response) {
    DubboEnterpriseLicense condition = new DubboEnterpriseLicense();
    condition.setEnterpriseName(request.getParameter("enterpriseName"));
    condition.setLicenseCode(request.getParameter("licenseCode"));
    condition.setOrganizationCode(request.getParameter("organizationCode"));
    if (StringUtils.isNotBlank(request.getParameter("validDateStart"))) {
        condition.setValidDateStart(DateUtil.getTimestamp(request.getParameter("validDateStart")));
    }/* ww  w.j av a  2  s.  c om*/
    if (StringUtils.isNotBlank(request.getParameter("validDateEnd"))) {
        condition.setValidDateEnd(DateUtil.getTimestamp(request.getParameter("validDateEnd")));
    }
    String type = request.getParameter("type") == null ? "" : request.getParameter("type");
    if ("0".equals(type)) {
        condition.setInvalidDateStart(DateUtil.getCurrent());
    } else if ("1".equals(type)) {
        condition.setInvalidDateStart(DateUtil.getCurrent());
        condition.setInvalidDateEnd(new Timestamp(DateUtil.addMonth(new Date(), 1).getTime()));
    } else if ("-1".equals(type)) {
        condition.setInvalidDateEnd(DateUtil.getCurrent());
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();
    try {
        resultMap = licenseService.getLicenses(condition, -1, 0);
        String title = "???";
        String[] headers = { "???", "?", "", "??", "??",
                "???", "", "??" };
        HSSFWorkbook wb = licenseService.ExcelOut(title, headers,
                (List<DubboEnterpriseLicense>) resultMap.get("list"), null);
        response.setContentType("application/vnd.ms-excel");
        String fileName = "licenses.xls";
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
    } catch (Exception e) {
        log.debug(e.getMessage(), e);
    }
}

From source file:com.truebanana.cache.AbstractDiskLruCache.java

private boolean writeToFile(byte[] data, OutputStream os) {
    try {//from  w w  w .  j  a  v a  2s. c o  m
        IOUtils.write(data, os);
        os.flush();
        os.close();
        Log.d("AbstractDiskLruCache", "Write file to disk successful");
        return true;
    } catch (IOException e) {
        Log.d("AbstractDiskLruCache", "Write file to disk failed");
        return false;
    }
}

From source file:io.github.kitarek.elasthttpd.plugins.consumers.file.consumer.HttpFileWriteRequestConsumer.java

void flushTheFile(File file, OutputStream outputStream, IOException e) {
    try {/*  w  w  w  .j a  va  2s. co m*/
        outputStream.flush();
    } catch (IOException e1) {
        LOGGER.error(format("There was an error with flushing stream to file: %s", file.getAbsolutePath()), e);
    }
}

From source file:com.esri.geoevent.test.performance.tcp.ProducerTcpSocketServer.java

/**
 * Send the event in a round robin fashion to distribute the load
 *
 * @param message to send/*www  . j ava  2 s.com*/
 */
public void sendEvent(String message) {
    Socket socket = clients.pop();
    try {
        OutputStream out = socket.getOutputStream();
        out.write(message.getBytes());
        out.flush();
    } catch (Exception error) {
        error.printStackTrace();
    }
    clients.push(socket);
}

From source file:com.iana.boesc.utility.BOESCUtil.java

/**
 * //www  .j  ava2  s .  c  o  m
 * @param list
 * @param outputStream
 * @throws DocumentException
 * @throws IOException
 */
public static void doMerge(List<InputStream> list, OutputStream outputStream)
        throws DocumentException, IOException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    for (InputStream in : list) {
        PdfReader reader = new PdfReader(in);
        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            document.newPage();
            // import the page from source pdf
            PdfImportedPage page = writer.getImportedPage(reader, i);
            // add the page to the destination pdf
            cb.addTemplate(page, 0, 0);
        }
    }

    outputStream.flush();
    document.close();
    outputStream.close();
}