Example usage for java.io BufferedInputStream close

List of usage examples for java.io BufferedInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:librarymanagementsystem.Base64Converter.java

/**
 * This method loads a file from file system and returns the byte array of
 * the content.//w w  w  .j a v a 2 s.  co m
 */
public static byte[] loadFileAsBytesArray(String fileName) throws Exception {

    File file = new File(fileName);
    int length = (int) file.length();
    BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file));
    byte[] bytes = new byte[length];
    reader.read(bytes, 0, length);
    reader.close();
    return bytes;

}

From source file:Main.java

public static void addEntryContent(ZipOutputStream zos, String entryFileName)
        throws IOException, FileNotFoundException {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(entryFileName));

    byte[] buffer = new byte[1024];
    int count = -1;
    while ((count = bis.read(buffer)) != -1) {
        zos.write(buffer, 0, count);//from ww w  .j  ava2  s. c  om
    }
    bis.close();
}

From source file:Main.java

public static void doCompressFile(String inFileName) {
    try {// w w w .  ja va2 s .c  om
        File file = new File(inFileName);
        FileOutputStream fos = new FileOutputStream(file + ".gz");
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        FileInputStream fin = new FileInputStream(file);
        BufferedInputStream in = new BufferedInputStream(fin);
        byte[] buffer = new byte[1024];
        int i;
        while ((i = in.read(buffer)) >= 0) {
            gzos.write(buffer, 0, i);
        }
        in.close();
        gzos.close();
    } catch (IOException e) {
        System.out.println("Exception is" + e);
    }
}

From source file:Main.java

public static byte[] readZipEntry(File zfile, ZipEntry entry) throws ZipException, IOException {
    Log.d("file3: ", zfile.toString());
    Log.d("zipEntry3: ", entry.toString());
    ZipFile zipFile = new ZipFile(zfile);
    if (entry != null && !entry.isDirectory()) {
        byte[] barr = new byte[(int) entry.getSize()];
        int read = 0;
        int len = 0;
        InputStream is = zipFile.getInputStream(entry);
        BufferedInputStream bis = new BufferedInputStream(is);
        int length = barr.length;
        while ((len = bis.read(barr, read, length - read)) != -1) {
            read += len;//from   ww  w  .  j a  va2  s.  c om
        }
        bis.close();
        is.close();
        zipFile.close();
        return barr;
    } else {
        zipFile.close();
        return new byte[0];
    }
}

From source file:Main.java

public static byte[] readByteArray(Context context, String fileName) throws IOException {

    byte[] data;/*from   w w w .ja v  a  2 s  .c  o m*/
    int c;

    FileInputStream fis = context.openFileInput(fileName);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    BufferedInputStream bos = new BufferedInputStream(fis);

    while ((c = bos.read()) != -1) {
        byteArrayOutputStream.write(c);
    }

    data = byteArrayOutputStream.toByteArray();

    bos.close();
    byteArrayOutputStream.close();
    fis.close();

    return data;
}

From source file:Util.java

public static void download(URL url, File to) throws IOException {
    BufferedInputStream in = new BufferedInputStream(url.openStream());
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(to));
    int bit = -1;
    while ((bit = in.read()) != -1) {
        out.write(bit);/*from   ww w . ja  v a2 s.  com*/
    }
    in.close();
    out.close();
}

From source file:documentToVector.spotlight.evaluation.external.AnnotationClient.java

protected static String readFileAsString(File file) throws IOException {
    byte[] buffer = new byte[(int) file.length()];
    BufferedInputStream f = new BufferedInputStream(new FileInputStream(file));
    f.read(buffer);// w  ww  . ja v a  2  s. c o m
    f.close();
    return new String(buffer);
}

From source file:Main.java

public static void saveISToFile(InputStream is, String fileName) throws IOException {
    File file = new File(fileName);
    file.getParentFile().mkdirs();//from  w w w .  ja va2s . com
    File tempFile = new File(fileName + ".tmp");
    FileOutputStream fos = new FileOutputStream(tempFile);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    BufferedInputStream bis = new BufferedInputStream(is);
    byte[] barr = new byte[32768];
    int read = 0;
    while ((read = bis.read(barr)) > 0) {
        bos.write(barr, 0, read);
    }
    bis.close();
    bos.flush();
    fos.flush();
    bos.close();
    fos.close();
    file.delete();
    tempFile.renameTo(file);
}

From source file:com.streamsets.datacollector.cluster.TarFileCreator.java

private static void addClasspath(String prefix, TarOutputStream out, List<URL> urls) throws IOException {
    if (urls != null) {
        for (URL url : urls) {
            File file = new File(url.getPath());
            String name = file.getName();
            if (name.endsWith(".jar")) {
                out.putNextEntry(new TarEntry(file, prefix + "/" + file.getName()));
                BufferedInputStream src = new BufferedInputStream(new FileInputStream(file), 65536);
                IOUtils.copy(src, out);/* w ww .j  a  v  a  2 s  .  c  o  m*/
                src.close();
                out.flush();
            }
        }
    }
}

From source file:Main.java

public static Bitmap revitionImageSize(String path) throws IOException {
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path)));
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from w  w  w.ja va 2 s  . co  m
    BitmapFactory.decodeStream(in, null, options);
    in.close();
    int i = 0;
    Bitmap bitmap = null;
    while (true) {
        if ((options.outWidth >> i <= 1000) && (options.outHeight >> i <= 1000)) {
            in = new BufferedInputStream(new FileInputStream(new File(path)));
            options.inSampleSize = (int) Math.pow(2.0D, i);
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeStream(in, null, options);
            break;
        }
        i += 1;
    }
    return bitmap;
}