Example usage for java.io OutputStream close

List of usage examples for java.io OutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with this stream.

Usage

From source file:com.github.rholder.gradle.dependency.DependencyConversionUtil.java

private static void dumpFromClasspath(String classpath, File outputFile) throws IOException {
    InputStream input = DependencyConversionUtil.class.getResourceAsStream(classpath);
    OutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile));
    IOUtils.copy(input, output);/*from  w w w .j a  v a 2 s.  c o m*/
    input.close();
    output.close();
}

From source file:com.appspresso.api.fs.FileSystemUtils.java

/**
 * OutputStream? ?./*from  w w w .  ja v a  2s.co  m*/
 * 
 * @param out ? OutputStream
 */
public static void closeQuietly(OutputStream out) {
    if (null != out) {
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.cloudera.oryx.kmeans.common.pmml.KMeansPMML.java

public static void write(File f, DataDictionary dictionary, List<? extends Model> models) throws IOException {
    OutputStream out = IOUtils.buildGZIPOutputStream(new FileOutputStream(f));
    try {/*from   w w w  . j  a  v  a 2 s  . c o m*/
        write(out, dictionary, models);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    } finally {
        out.close();
    }
}

From source file:net.sourceforge.lept4j.util.LoadLibs.java

/**
 * Copies resources from the jar file of the current thread and extract it
 * to the destination directory./*from  w ww  . jav  a2s.  c om*/
 *
 * @param jarConnection
 * @param destDir
 */
static void copyJarResourceToDirectory(JarURLConnection jarConnection, File destDir) {
    try {
        JarFile jarFile = jarConnection.getJarFile();
        String jarConnectionEntryName = jarConnection.getEntryName() + "/";

        /**
         * Iterate all entries in the jar file.
         */
        for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
            JarEntry jarEntry = e.nextElement();
            String jarEntryName = jarEntry.getName();

            /**
             * Extract files only if they match the path.
             */
            if (jarEntryName.startsWith(jarConnectionEntryName)) {
                String filename = jarEntryName.substring(jarConnectionEntryName.length());
                File currentFile = new File(destDir, filename);

                if (jarEntry.isDirectory()) {
                    currentFile.mkdirs();
                } else {
                    currentFile.deleteOnExit();
                    InputStream is = jarFile.getInputStream(jarEntry);
                    OutputStream out = FileUtils.openOutputStream(currentFile);
                    IOUtils.copy(is, out);
                    is.close();
                    out.close();
                }
            }
        }
    } catch (IOException e) {
        logger.log(Level.WARNING, e.getMessage(), e);
    }
}

From source file:Main.java

public static void createCacheFileFromStream(Bitmap bitmap, String path) {
    File file = new File(path);
    OutputStream out = null;
    try {//  w  w w  .  ja va2 s  . c  om
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.intera.roostrap.util.EncryptionUtil.java

private static void doCopy(InputStream is, OutputStream os) throws IOException {
    byte[] bytes = new byte[64];
    int numBytes;
    while ((numBytes = is.read(bytes)) != -1) {
        os.write(bytes, 0, numBytes);//from   ww  w .ja  v  a 2 s.  c om
    }
    os.flush();
    os.close();
    is.close();
}

From source file:FileCopyUtils.java

/**
 * Copy the contents of the given byte array to the given OutputStream.
 * Closes the stream when done./*from   w w  w.j  a v a  2  s .  c  o m*/
 * @param in the byte array to copy from
 * @param out the OutputStream to copy to
 * @throws IOException in case of I/O errors
 */
public static void copy(byte[] in, OutputStream out) throws IOException {

    try {
        out.write(in);
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            System.out.println("Could not close OutputStream:" + ex);
        }
    }
}

From source file:Main.java

public static void unzip(String zipFilePath, String fileName) {

    try {//from  www.j a  v  a  2s  . com
        FileInputStream fin = new FileInputStream(zipFilePath);
        ZipInputStream zin = new ZipInputStream(fin);

        do {
            // no-op
        } while (!zin.getNextEntry().getName().equals(fileName));

        OutputStream os = new FileOutputStream(fileName);

        byte[] buffer = new byte[1024];
        int length;

        //read the entry from zip file and extract it to disk
        while ((length = zin.read(buffer)) > 0) {
            os.write(buffer, 0, length);
        }
        os.close();
        zin.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.predic8.membrane.examples.DistributionExtractingTestcase.java

public static final void copyInputStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int len;//from ww  w .j  a  v  a  2s.c o  m

    while ((len = in.read(buffer)) >= 0)
        out.write(buffer, 0, len);

    in.close();
    out.close();
}

From source file:Main.java

public static void readFullyWriteToOutputStream(@NonNull InputStream in, @NonNull OutputStream out)
        throws IOException {
    try {// w  w w.j  a  v  a 2  s .c  o  m
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) > 0) {
            out.write(buffer, 0, bytesRead);
        }
        out.flush();
    } finally {
        out.close();
    }
}