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.buaa.cfs.io.nativeio.SharedFileDescriptorFactory.java

/**
 * Create a new SharedFileDescriptorFactory.
 *
 * @param prefix       The prefix to prepend to all the file names created
 *                       by this factory.
 * @param paths        An array of paths to use.  We will try each path in
 *                       succession, and return a factory using the first
 *                       usable path.//from   www.  ja  v  a  2 s .  co  m
 * @return The factory.
 * @throws IOException If a factory could not be created for any reason.
 */
public static SharedFileDescriptorFactory create(String prefix, String paths[]) throws IOException {
    String loadingFailureReason = getLoadingFailureReason();
    if (loadingFailureReason != null) {
        throw new IOException(loadingFailureReason);
    }
    if (paths.length == 0) {
        throw new IOException("no SharedFileDescriptorFactory paths were " + "configured.");
    }
    StringBuilder errors = new StringBuilder();
    String strPrefix = "";
    for (String path : paths) {
        try {
            FileInputStream fis = new FileInputStream(createDescriptor0(prefix + "test", path, 1));
            fis.close();
            deleteStaleTemporaryFiles0(prefix, path);
            return new SharedFileDescriptorFactory(prefix, path);
        } catch (IOException e) {
            errors.append(strPrefix).append("Error creating file descriptor in ").append(path).append(": ")
                    .append(e.getMessage());
            strPrefix = ", ";
        }
    }
    throw new IOException(errors.toString());
}

From source file:com.ewcms.common.io.HtmlFileUtil.java

public static byte[] readByte(String fileName) {
    try {//from www  . j  a  v a 2  s  . com
        fileName = normalizePath(fileName);
        FileInputStream fis = new FileInputStream(fileName);
        byte r[] = new byte[fis.available()];
        fis.read(r);
        fis.close();
        return r;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static void gzipIt(String inputFile, String outputFile) {

    byte[] buffer = new byte[1024];

    try {//  w  w  w .jav a 2s .  c om

        GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(outputFile));

        FileInputStream in = new FileInputStream(inputFile);

        int len;
        while ((len = in.read(buffer)) > 0) {
            gzos.write(buffer, 0, len);
        }

        in.close();

        gzos.finish();
        gzos.close();

        System.out.println("Done");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static String getSimID() {
    // TODO Auto-generated method stub
    Log.v(TAG, "getSimID() called");
    String simID = "";
    try {//from  w w w.ja v a2s  .com
        FileInputStream is = new FileInputStream(SIMCARD_PATH);
        DataInputStream dis = new DataInputStream(is);
        simID = dis.readLine();
        simID = simID.trim();
        is.close();
        dis.close();
        return simID;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        Log.v(TAG, "getSimID exception: do not have a SIM Card!", e);
        return "123456";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.v(TAG, "getSimID exception: read IOException", e);
        return "";
    }

}

From source file:edu.berkeley.compbio.ncbitaxonomy.service.NcbiTaxonomyServicesContextFactory.java

public static ApplicationContext makeNcbiTaxonomyServicesContext() throws IOException {

    File propsFile = PropertiesUtils.findPropertiesFile("NCBI_TAXONOMY_SERVICE_PROPERTIES", ".ncbitaxonomy",
            "service.properties");

    logger.debug("Using properties file: " + propsFile);
    Properties p = new Properties();
    FileInputStream is = null;
    try {/*  w ww.  ja  v  a2 s.c  o  m*/
        is = new FileInputStream(propsFile);
        p.load(is);
    } finally {
        is.close();
    }
    String dbName = (String) p.get("default");

    Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p);

    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomyclient.xml"));

    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    Properties properties = databases.get(dbName);

    if (properties == null) {
        logger.error("Service definition not found: " + dbName);
        logger.error("Valid names: " + StringUtils.join(databases.keySet().iterator(), ", "));
        throw new NcbiTaxonomyRuntimeException("Database definition not found: " + dbName);
    }

    cfg.setProperties(properties);
    ctx.addBeanFactoryPostProcessor(cfg);

    ctx.refresh();

    // add a shutdown hook for the above context...
    ctx.registerShutdownHook();

    return ctx;
}

From source file:foss.filemanager.core.Utils.java

public static String md5sum(File file) throws IOException {
    FileInputStream fis = new FileInputStream(file);
    String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
    fis.close();
    return md5;/*from   w ww .java2 s.com*/
}

From source file:com.bazaarvoice.jolt.JoltCliUtilities.java

/**
 * Uses the File to build a Map containing JSON data found in the file. This method will
 * System exit with an error code of 1 if has any trouble opening the file or the file did not
 * contain properly formatted JSON (i.e. the JSON parser was unable to parse its contents)
 *
 * @return the Map containing the JSON data
 *///w  w w  .j  av  a2 s .  c  o m
public static Object createJsonObjectFromFile(File file, boolean suppressOutput) {
    Object jsonObject = null;
    try {
        FileInputStream inputStream = new FileInputStream(file);
        jsonObject = JsonUtils.jsonToObject(inputStream);
        inputStream.close();
    } catch (IOException e) {
        if (e instanceof JsonParseException) {
            printToStandardOut("File " + file.getAbsolutePath() + " did not contain properly formatted JSON.",
                    suppressOutput);
        } else {
            printToStandardOut("Failed to open file: " + file.getAbsolutePath(), suppressOutput);
        }
        System.exit(1);
    }
    return jsonObject;
}

From source file:S3ClientSideEncryptionWithSymmetricMasterKey.java

public static SecretKey loadSymmetricAESKey(String path, String algorithm)
        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException {
    // Read private key from file.
    File keyFile = new File(path + "/" + keyName);
    FileInputStream keyfis = new FileInputStream(keyFile);
    byte[] encodedPrivateKey = new byte[(int) keyFile.length()];
    keyfis.read(encodedPrivateKey);/*from ww  w.ja va 2  s  .c om*/
    keyfis.close();

    // Generate secret key.
    return new SecretKeySpec(encodedPrivateKey, "AES");
}

From source file:com.aionemu.commons.utils.PropertiesUtils.java

/**
 * Loads properties by given file//from ww  w.ja v  a  2  s  . c om
 *
 * @param file filename
 * @return loaded properties
 * @throws java.io.IOException if can't load file
 */
public static Properties load(File file) throws IOException {
    FileInputStream fis = new FileInputStream(file);
    Properties p = new Properties();
    p.load(fis);
    fis.close();
    return p;
}

From source file:Main.java

/**
 * Creates a copy of the file, ensuring the file is written to the disk
 * @param in Source file//ww w.jav  a2  s  . c  om
 * @param out Destination file
 * @throws IOException if the operation fails
 */
public static void copyFileSync(File in, File out) throws IOException {
    FileInputStream inStream = new FileInputStream(in);
    FileOutputStream outStream = new FileOutputStream(out);
    try {
        copyStream(inStream, outStream);
    } finally {
        inStream.close();
        outStream.flush();
        outStream.getFD().sync();
        outStream.close();
    }
}