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:com.apps.android.viish.encyclolpedia.tools.ImageManager.java

public static boolean isFileExists(Context context, String fileName) {
    try {//from  ww  w  . j av a 2s. c  o m
        FileInputStream fis = getFileInputStream(context, fileName);
        fis.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * See: http://stackoverflow.com/questions/477572/android-strange
 *       -out-of-memory-issue-while-loading-an-image
 *       -to-a-bitmap-object/823966#823966
 * Thanks to StackOverflow user named Fedor.
 *//*from   ww w  .j av  a  2 s .  com*/
public static Bitmap decodeFile(File f, int size) {
    Bitmap b = null;
    try {
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > size || o.outWidth > size) {
            scale = (int) Math.pow(2.0, (int) Math
                    .round(Math.log(size / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inTempStorage = new byte[32 * 1024];
        o2.inPurgeable = true;
        o2.inSampleSize = scale;
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (IOException e) {
    }
    return b;
}

From source file:fi.laverca.examples.util.ExampleConf.java

/**
 * Get the properties object of this configuration
 * @param confPath Configuration file path
 * @return Java Properties containing the configuration
 *//*from w  w w. j a va2  s.  co  m*/
public static Properties getProperties(final String confPath) {
    File f = new File(confPath);
    Properties properties = new Properties();
    FileInputStream is;
    try {
        is = new FileInputStream(f);
        properties.load(is);
        is.close();
    } catch (Exception e) {
        log.fatal("Could not load properties");
    }
    return properties;
}

From source file:info.bitoo.Main.java

static Properties readConfiguration(CommandLine cmd) {
    /*/*from w  w w .  j a  v a2s .co  m*/
     * Read configuration file
     */
    String configFilename = defaultConfigFilename;
    if (cmd.hasOption("c")) {
        configFilename = cmd.getOptionValue("c");
    }

    Properties props = new Properties();
    try {
        FileInputStream fis = new FileInputStream(configFilename);
        props.load(fis);
        fis.close();
        PropertyConfigurator.configure(props);
        logger.debug("Log4j initialized");
    } catch (FileNotFoundException e) {
        System.out.println("Configuration file not found: [" + configFilename + "]");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Bad configuration file: [" + configFilename + "]");
        e.printStackTrace();
    }
    return props;
}

From source file:Main.java

public static byte[] getFileByte(File file) {
    if (!file.exists()) {
        return null;
    }/* w w w . jav a 2  s  . c  o m*/
    try {
        FileInputStream fis = new FileInputStream(file);
        int len = fis.available();
        byte[] bytes = new byte[len];
        fis.read(bytes);
        fis.close();
        return bytes;
    } catch (Exception e) {

    }

    return null;
}

From source file:Main.java

public static Object readObj(String fileName) {
    Object obj = new Object();
    try {/* w w  w .  j av a  2 s.c  o m*/
        FileInputStream fin = new FileInputStream(fileName);
        ObjectInputStream oin = new ObjectInputStream(fin);
        obj = oin.readObject();
        fin.close();
        oin.close();
    } catch (Exception e) {
        printE("OpusTool", e);
    } finally {
        return obj;
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T readSerializedObject(Context context, String fileName)
        throws FileNotFoundException, IOException, ClassNotFoundException {
    FileInputStream fis = context.openFileInput(fileName);
    ObjectInputStream in = new ObjectInputStream(fis);

    T out = (T) in.readObject();/*from  ww w .  j a  va 2s .c  om*/

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

From source file:Main.java

/**
 * Get contents of a file as String//from  ww  w  .j  a  v  a2s .  c om
 *
 * @param filePath File path as String
 * @return Contents of the file
 * @throws IOException
 */
public static String getContentsAsString(String filePath) throws IOException {
    File fl = new File(filePath);
    FileInputStream fin = new FileInputStream(fl);
    String ret = convertStreamToString(fin);
    //Make sure you close all streams.
    fin.close();
    return ret;
}

From source file:Main.java

public static String getCurrentProject() {
    try {/*  ww w.j  av a2s .c o  m*/
        String value = "";
        Properties properties = new Properties();
        FileInputStream inputFile = new FileInputStream(System.getProperty("user.dir") + "/system.properties");
        properties.load(inputFile);
        inputFile.close();

        if (properties.containsKey("ProjectPath")) {
            value = properties.getProperty("ProjectPath");
            String resultName = new String(value.getBytes("ISO-8859-1"), "gbk");
            return resultName;
        } else
            return value;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static Object objectXmlDecoder(String objSource) {
    Object obj = null;/*from ww w.j ava2 s.co  m*/
    try {
        File fin = new File(objSource);
        if (fin.exists()) {
            FileInputStream fis = new FileInputStream(fin);
            XMLDecoder decoder = new XMLDecoder(fis);
            obj = decoder.readObject();
            fis.close();
            decoder.close();
        }
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return obj;
}