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:Main.java

public static void copy(InputStream in, OutputStream out) throws IOException {
    byte[] buf = new byte[1024];
    int len;/*from   w  w w .  j a  va2s  . c  o  m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.flush();
    in.close();
    out.close();
}

From source file:Utils.java

/**
 * Copy in stream to an out stream/*w  w w .  jav a  2s  . c o m*/
 * 
 * @param in
 * @param out
 * @throws IOException
 */
public static void copyInputStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int len = in.read(buffer);
    while (len >= 0) {
        out.write(buffer, 0, len);
        len = in.read(buffer);
    }
    in.close();
    out.close();
}

From source file:it.unicaradio.android.gcm.GcmServerRpcCall.java

/**
 * @param bytes/* w  ww . jav  a  2  s. c  o m*/
 * @param conn
 * @throws IOException
 */
private static void postRequest(HttpURLConnection conn, byte[] bytes) throws IOException {
    OutputStream out = conn.getOutputStream();
    out.write(bytes);
    out.close();
}

From source file:Main.java

public static void copy(InputStream inputstream, OutputStream outputstream) throws IOException {
    byte abyte0[] = new byte[50000];
    do {//w  ww . ja  v  a  2  s .  c o m
        int i = inputstream.read(abyte0);
        if (i > 0) {
            outputstream.write(abyte0, 0, i);
        } else {
            outputstream.close();
            return;
        }
    } while (true);
}

From source file:brut.util.OS.java

public static void cpdir(File src, File dest) throws BrutException {
    dest.mkdirs();/*from   ww w. ja va  2s. c o  m*/
    File[] files = src.listFiles();
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        File destFile = new File(dest.getPath() + File.separatorChar + file.getName());
        if (file.isDirectory()) {
            cpdir(file, destFile);
            continue;
        }
        try {
            InputStream in = new FileInputStream(file);
            OutputStream out = new FileOutputStream(destFile);
            IOUtils.copy(in, out);
            in.close();
            out.close();
        } catch (IOException ex) {
            throw new BrutException("Could not copy file: " + file, ex);
        }
    }
}

From source file:com.cats.version.utils.Utils.java

public static void closeRes(OutputStream fos) {
    if (null != fos) {
        try {/*from w w  w  .  j  a  va 2s . com*/
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void setupDatabase(Context context, String db_name) {
    ContextWrapper cw = new ContextWrapper(context);
    String db_path = cw.getDatabasePath(db_name).getPath();

    try {/*w w w  .  jav  a2  s  . c o  m*/
        // Setup
        byte[] buffer = new byte[1024];
        int length;
        InputStream myInput = context.getAssets().open(db_name);
        OutputStream myOutput = new FileOutputStream(db_path);

        // Write all the things.
        while ((length = myInput.read(buffer)) > 0)
            myOutput.write(buffer, 0, length);

        // Cleanup
        myOutput.close();
        myOutput.flush();
        myInput.close();
    } catch (IOException e) {
        // You done goofed.
        e.printStackTrace();
    }
}

From source file:Main.java

public static File saveTmpFile(InputStream is) throws Exception {
    File file = getTmpFile();//ww w  . j a  v  a  2 s  . c  o  m
    OutputStream os = new FileOutputStream(file);

    byte[] buf = new byte[1024];
    int len = 0;

    while ((len = is.read(buf)) > 0) {
        os.write(buf, 0, len);
    }

    os.flush();
    os.close();

    return file;
}

From source file:Main.java

public static void copy(InputStream src, File dst) throws IOException {
    OutputStream out = new FileOutputStream(dst);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;//from   w  w w .ja  va2  s  .  com
    while ((len = src.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    src.close();
    out.close();
}

From source file:accumulo.AccumuloStuff.java

private static void setCoreSite(MiniAccumuloClusterImpl cluster) throws Exception {
    File csFile = new File(cluster.getConfig().getConfDir(), "core-site.xml");
    if (csFile.exists())
        throw new RuntimeException(csFile + " already exist");

    Configuration coreSite = new Configuration(false);
    coreSite.set("fs.file.impl", RawLocalFileSystem.class.getName());
    OutputStream out = new BufferedOutputStream(
            new FileOutputStream(new File(cluster.getConfig().getConfDir(), "core-site.xml")));
    coreSite.writeXml(out);//from   ww w  .  j a  v  a2s .com
    out.close();
}