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:eu.cloud4soa.governance.ems.util.ExecutionManagementUtil.java

public static String getCloudFoundryAdapterPath() {
    System.out.println(ExecutionManagementUtil.class.getClassLoader()
            .getResourceAsStream("extras/CloudFoundryC4SAdapter-1.0-SNAPSHOT.war"));
    String path = "";
    try {//  ww  w .ja  v  a2 s.  c  om
        InputStream inputStream = ExecutionManagementUtil.class.getClassLoader()
                .getResourceAsStream("extras/CloudFoundryC4SAdapter-1.0-SNAPSHOT.war");
        // write the inputStream to a FileOutputStream
        File tmp_file = new File(
                System.getProperty("java.io.tmpdir") + "/" + "CloudFoundryC4SAdapter-1.0-SNAPSHOT.war");
        OutputStream out = new FileOutputStream(tmp_file);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = inputStream.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }

        inputStream.close();
        out.flush();
        out.close();

        logger.debug("New file created!");

        path = tmp_file.getCanonicalPath();
        logger.debug(path);
    } catch (IOException e) {
        logger.debug(e.getMessage());
    }

    return path;
}

From source file:eu.cloud4soa.governance.ems.util.ExecutionManagementUtil.java

public static String getBeanstalkAdapterPath() {
    System.out.println(ExecutionManagementUtil.class.getClassLoader()
            .getResourceAsStream("extras/BeanstalkC4SAdapter-1.0-SNAPSHOT.war"));
    String path = "";
    try {//from  w w w. j a v  a2 s . c om
        InputStream inputStream = ExecutionManagementUtil.class.getClassLoader()
                .getResourceAsStream("extras/BeanstalkC4SAdapter-1.0-SNAPSHOT.war");
        // write the inputStream to a FileOutputStream
        File tmp_file = new File(
                System.getProperty("java.io.tmpdir") + "/" + "BeanstalkC4SAdapter-1.0-SNAPSHOT.war");
        OutputStream out = new FileOutputStream(tmp_file);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = inputStream.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }

        inputStream.close();
        out.flush();
        out.close();

        logger.debug("New file created!");

        path = tmp_file.getCanonicalPath();
        logger.debug(path);
    } catch (IOException e) {
        logger.debug(e.getMessage());
    }

    return path;
}

From source file:com.iflytek.spider.util.DomUtil.java

/**
 * save dom into ouputstream/*from  ww w .j  a v a 2s  .  c  om*/
 * 
 * @param os
 * @param e
 */
public static void saveDom(OutputStream os, Element e) {

    DOMSource source = new DOMSource(e);
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = transFactory.newTransformer();
        transformer.setOutputProperty("indent", "yes");
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);
        os.flush();
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace(LogUtil.getWarnStream(LOG));
    } catch (IOException e1) {
        e1.printStackTrace(LogUtil.getWarnStream(LOG));
    } catch (TransformerConfigurationException e2) {
        e2.printStackTrace(LogUtil.getWarnStream(LOG));
    } catch (TransformerException ex) {
        ex.printStackTrace(LogUtil.getWarnStream(LOG));
    }
}

From source file:com.uphyca.kitkat.storage.internal.impl.LiveSdkSkyDriveClient.java

private static void drain(InputStream in, File dest) throws IOException {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
    try {//from w ww. j  a va 2  s.c  o  m
        byte[] buf = new byte[8192];
        for (int c; (c = in.read(buf)) > -1;) {
            out.write(buf, 0, c);
        }
        out.flush();
    } finally {
        closeQuietly(out);
    }
}

From source file:fr.aliasource.webmail.server.proxy.client.http.UploadAttachmentMethod.java

/**
 * Fast stream transfer method//from  w w  w. ja  v  a2s . co m
 * 
 * @param in
 * @param out
 * @throws IOException
 */
public static void transfer(InputStream in, OutputStream out, boolean closeIn) throws IOException {
    final byte[] buffer = new byte[2048];

    try {
        while (true) {
            int amountRead = in.read(buffer);
            if (amountRead == -1) {
                break;
            }
            out.write(buffer, 0, amountRead);
        }
    } finally {
        if (closeIn) {
            in.close();
        }
        out.flush();
        out.close();
    }
}

From source file:net.mindengine.oculus.frontend.web.controllers.display.FileDisplayController.java

public static void showTextFile(HttpServletResponse response, String path, String fileName, String contentType)
        throws IOException {

    OutputStream os = response.getOutputStream();
    OutputStreamWriter w = new OutputStreamWriter(os);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    response.setContentType(contentType);
    response.setCharacterEncoding("UTF-8");
    String content = readFileAsString(path);
    w.write(content);/*w  w w  .  ja  v a 2s  .c om*/
    w.flush();
    os.flush();
    os.close();
}

From source file:eu.cloud4soa.governance.ems.util.ExecutionManagementUtil.java

public static String getCloudBeesAdapterPath() {
    //        System.out.println( ClassLoader.getSystemResource("extras/CloudBeesC4SAdapter-1.0-SNAPSHOT.war"));
    System.out.println(ExecutionManagementUtil.class.getClassLoader()
            .getResourceAsStream("extras/CloudBeesC4SAdapter-1.0-SNAPSHOT.war"));
    String path = "";
    try {/*from   w  w w.  j a  v a 2s. co  m*/
        //        InputStream inputStream=ClassLoader.getSystemResourceAsStream("extras/CloudBeesC4SAdapter-1.0-SNAPSHOT.war");
        InputStream inputStream = ExecutionManagementUtil.class.getClassLoader()
                .getResourceAsStream("extras/CloudBeesC4SAdapter-1.0-SNAPSHOT.war");
        // write the inputStream to a FileOutputStream
        File tmp_file = new File(
                System.getProperty("java.io.tmpdir") + "/" + "CloudBeesC4SAdapter-1.0-SNAPSHOT.war");
        OutputStream out = new FileOutputStream(tmp_file);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = inputStream.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }

        inputStream.close();
        out.flush();
        out.close();

        logger.debug("New file created!");

        path = tmp_file.getCanonicalPath();
        logger.debug(path);
    } catch (IOException e) {
        logger.debug(e.getMessage());
    }

    return path;
}

From source file:com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeechTest.java

/**
 * Write input stream to output stream.//from  w  ww  .j ava 2 s  . co m
 * 
 * @param inputStream
 *            the input stream
 * @param outputStream
 *            the output stream
 */
private static void writeInputStreamToOutputStream(InputStream inputStream, OutputStream outputStream) {
    try {
        try {
            final byte[] buffer = new byte[1024];
            int read;

            while ((read = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, read);
            }

            outputStream.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            outputStream.close();
            inputStream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void copyFile(Context ctx, String filename) throws IOException {
    InputStream in = null;/*from ww  w  . j av  a2s  . c om*/
    OutputStream out = null;

    in = ctx.getApplicationContext().getAssets().open(filename);
    StringBuilder newFileName = new StringBuilder();
    newFileName.append(DATA_DIR).append(ctx.getPackageName()).append("/").append(filename);
    out = new FileOutputStream(newFileName.toString());

    byte[] buffer = new byte[1024];
    int read;
    while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
    }
    in.close();
    in = null;
    out.flush();
    out.close();
    out = null;
}

From source file:fr.zcraft.zlib.tools.mojang.UUIDFetcher.java

/**
 * Writes a JSON body in this connection from the given list.
 *
 * @param connection The connection.//from   w  w w  .j av a  2  s. c  om
 * @param names      The list to write as a JSON object.
 *
 * @throws IOException If an exception occurred while contacting the server.
 */
private static void writeBody(HttpURLConnection connection, List<String> names) throws IOException {
    OutputStream stream = connection.getOutputStream();
    String body = JSONArray.toJSONString(names);
    stream.write(body.getBytes());
    stream.flush();
    stream.close();
}