Example usage for java.io FileInputStream close

List of usage examples for java.io FileInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

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

Usage

From source file:jedi.util.serialization.Pickle.java

/**
 * Deserializes objects.//from w  w w . ja va  2  s  .c  o  m
 * 
 * @param f File that holds the serialized objects.
 * @return Object
 */
public static Object load(File f) {
    Object o = null;

    if (f != null) {
        try {
            FileInputStream fis = new FileInputStream(f);

            // The file reader.
            ObjectInputStream ois = new ObjectInputStream(fis);
            o = ois.readObject();
            ois.close();

            fis.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return o;
}

From source file:Main.java

public static Bitmap getBitmap(Context context, String fileName) {
    FileInputStream fis = null;
    Bitmap bitmap = null;/* w w  w.  j a v a2  s  .  c  o  m*/
    try {
        fis = context.openFileInput(fileName);
        bitmap = BitmapFactory.decodeStream(fis);
    } catch (FileNotFoundException | OutOfMemoryError e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getBitmap(Context context, String fileName) {
    FileInputStream fis = null;
    Bitmap bitmap = null;/* w  w w. j a  v a 2s. c  o  m*/
    try {
        fis = context.openFileInput(fileName);
        bitmap = BitmapFactory.decodeStream(fis);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    } finally {
        try {
            fis.close();
        } catch (Exception e) {
        }
    }
    return bitmap;
}

From source file:ch.admin.suis.msghandler.util.ZipUtils.java

private static void isInValid(FileLock lock, FileInputStream in) throws IOException {
    if (lock == null) {
        // the lock cannot be taken, report an Exception
        // First, we need to close the FileInputStream, otherwise it's gonna mess things around
        in.close(); // Could throw an IOException but it's pretty much what's going to happen here.
        throw new IOException(
                "cannot apply lock to the file {0}, the file is probably locked by another application");
    }//from w  ww.j a  va2  s . c om
}

From source file:Main.java

public static byte[] readFileToMemory(String file) throws IOException {
    FileInputStream fis = new FileInputStream(file);
    FileChannel fileChannel = fis.getChannel();
    long size = fileChannel.size();
    MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, size);
    byte[] data = new byte[(int) size];
    mappedByteBuffer.get(data, 0, (int) size);
    fileChannel.close();/* w  w w .j a v  a  2 s. c  o  m*/
    fis.close();
    return data;
    //      return readFileToMemory(new File(file));
}

From source file:com.evolveum.midpoint.testing.model.client.sample.RunScript.java

private static String readXmlFile(String filename) throws IOException {
    String encoding = determineEncoding(filename);
    FileInputStream fis = new FileInputStream(filename);
    String data = IOUtils.toString(fis, encoding);
    fis.close();
    return data;/*from w  w w  .ja  v  a2 s.c o  m*/
}

From source file:JarMaker.java

/**
 * used by downloadAndPack//from   w w  w  . j  a  va  2  s  .c om
 * @param _jout
 * @param _dir
 * @param _prefix
 * @throws IOException
 */
public static void add(JarOutputStream _jout, File _dir, String _prefix) throws IOException {

    File[] content = _dir.listFiles();
    if (_dir.isDirectory()) {
        for (int i = 0, l = content.length; i < l; ++i) {
            if (content[i].isDirectory()) {
                _jout.putNextEntry(
                        new ZipEntry(_prefix + (_prefix.equals("") ? "" : "/") + content[i].getName() + "/"));
                add(_jout, content[i], _prefix + (_prefix.equals("") ? "" : "/") + content[i].getName());
            } else {
                _jout.putNextEntry(
                        new ZipEntry(_prefix + (_prefix.equals("") ? "" : "/") + content[i].getName()));
                FileInputStream in = new FileInputStream(content[i]);
                write(in, _jout);
                in.close();
            }
        }
    } else {
        _jout.putNextEntry(new ZipEntry(_prefix + (_prefix.equals("") ? "" : "/") + _dir.getName()));
        FileInputStream in = new FileInputStream(_dir);
        write(in, _jout);
        in.close();
    }
}

From source file:com.fredhopper.core.connector.index.FileUtils.java

public static void addToZipFile(final File file, final ZipOutputStream zos) throws IOException {

    final FileInputStream fis = new FileInputStream(file);
    final ZipEntry zipEntry = new ZipEntry(file.getName());
    zos.putNextEntry(zipEntry);/*from www  .j  a v a  2  s  . c o  m*/

    final byte[] bytes = new byte[1024];
    int length;
    while ((length = fis.read(bytes)) >= 0) {
        zos.write(bytes, 0, length);
    }

    zos.closeEntry();
    fis.close();
}

From source file:es.chatclient.styles.CssGenerator.java

private static String replaceConstants(File f) {

    FileInputStream fis;
    try {// w  w w  . j  av a 2 s.  c  om

        fis = new FileInputStream(f);
        String content = IOUtils.toString(fis, Charset.defaultCharset());

        for (Object key : propCss.keySet()) {
            content = content.replaceAll(key.toString(), propCss.get(key).toString());
        }

        fis.close();

        return content;

    } catch (FileNotFoundException ex) {
        Logger.getLogger(CssGenerator.class.getName()).log(Level.SEVERE, null, ex);

    } catch (IOException ex) {
        Logger.getLogger(CssGenerator.class.getName()).log(Level.SEVERE, null, ex);

    }
    return null;
}

From source file:Main.java

public static synchronized boolean downloadFileMD5Check(File f, String expectedMD5) {
    boolean flag = false;
    try {/*from w  w w.java  2s .  c o m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        FileInputStream fis = new FileInputStream(f);
        byte[] b = new byte[1024];
        int len = 0;
        while ((len = fis.read(b)) != -1) {
            md.update(b, 0, len);
        }

        if (md5(md).equals(expectedMD5)) {
            flag = true;
        }
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return flag;
}