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:eu.stratosphere.nephele.jobmanager.web.LogfileInfoServlet.java

private static void writeFile(OutputStream out, File file) throws IOException {
    byte[] buf = new byte[4 * 1024]; // 4K buffer

    FileInputStream is = null;
    try {//  w w w  . j av a2s  .  c om
        is = new FileInputStream(file);

        int bytesRead;
        while ((bytesRead = is.read(buf)) != -1) {
            out.write(buf, 0, bytesRead);
        }
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:Main.java

public static void zipMutiCompress(File[] srcfile, File destFile) {
    byte[] buf = new byte[BUFFERED_SIZE];
    try {//from  ww w.  ja va  2 s .  co  m
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destFile));
        if (null != srcfile && srcfile.length > 0) {
            for (int i = 0; i < srcfile.length; i++) {
                File file = srcfile[i];
                if (null != file) {
                    FileInputStream in = new FileInputStream(file);
                    out.putNextEntry(new ZipEntry(file.getName()));
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                    out.closeEntry();
                    in.close();
                }
            }
        }
        out.close();
    } catch (IOException e) {

    }
}

From source file:Main.java

public static byte[] fileToByte(String filePath) throws Exception {
    byte[] data = new byte[0];
    File file = new File(filePath);
    if (file.exists()) {
        FileInputStream in = new FileInputStream(file);
        ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
        byte[] cache = new byte[CACHE_SIZE];
        int nRead = 0;
        while ((nRead = in.read(cache)) != -1) {
            out.write(cache, 0, nRead);/*from   w w  w . j a  v a 2  s  .c  o  m*/
            out.flush();
        }
        out.close();
        in.close();
        data = out.toByteArray();
    }
    return data;
}

From source file:net.geoprism.SystemLogoSingletonDTO.java

/**
 * Uploads a mini logo file to the server for persistance. Calling this method will also populate the client-side
 * cache for future calls to getMiniLogoFilePath.
 * //from   ww w .ja v  a 2 s  .  co m
 * @param clientRequest
 * @param fileStream
 * @param fileName
 */
public static void uploadMiniLogoAndCache(com.runwaysdk.constants.ClientRequestIF clientRequest,
        java.io.InputStream fileStream, java.lang.String fileName) {
    String tempDir = LocalProperties.getJspDir() + "/../uploaded_images";
    new File(tempDir).mkdir();
    miniLogoCache = new File(tempDir, fileName);

    try {
        // Write the file locally to our cache
        FileOutputStream fos = new FileOutputStream(miniLogoCache);
        BufferedOutputStream buffer = new BufferedOutputStream(fos);
        IOUtils.copy(fileStream, buffer);
        buffer.close();
        fos.close();

        // Send the cache file to the server for vault persistance.
        FileInputStream serverInput = new FileInputStream(miniLogoCache);
        SystemLogoSingletonDTOBase.uploadMiniLogo(clientRequest, serverInput, fileName);
        serverInput.close();
    } catch (IOException e) {
        logger.error("Error creating image file [" + fileName + "].", e);
        return;
    }
}

From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.AbstractSslContext.java

protected static KeyManager[] createKeyManager(JSONObject sslConf) {
    KeyManager[] kms = null;/*ww w  . j  a  v a  2 s  .  c om*/
    try {
        String CERT_STORE = "etc/conf/server.p12";
        String CERT_STORE_PASSWORD = "Changeme_123";
        String KEY_STORE_TYPE = "PKCS12";
        if (sslConf != null) {
            CERT_STORE = sslConf.getString("keyStore");
            CERT_STORE_PASSWORD = sslConf.getString("keyStorePass");
            KEY_STORE_TYPE = sslConf.getString("keyStoreType");
        }
        // load jks file
        FileInputStream f_certStore = new FileInputStream(CERT_STORE);
        KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE);
        ks.load(f_certStore, CERT_STORE_PASSWORD.toCharArray());
        f_certStore.close();

        // init and create
        String alg = KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg);
        kmFact.init(ks, CERT_STORE_PASSWORD.toCharArray());

        kms = kmFact.getKeyManagers();
    } catch (Exception e) {
        LOG.error("create KeyManager fail!", e);
    }
    return kms;
}

From source file:Main.java

public static Bitmap getBitmapByFile(File file) {
    FileInputStream fis = null;
    Bitmap bitmap = null;/*from w w w  .  ja v  a2 s  .c om*/
    try {
        fis = new FileInputStream(file);
        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:com.btoddb.fastpersitentqueue.speedtest.SpeedTestConfig.java

public static SpeedTestConfig create(String configFilename) throws FileNotFoundException {
    Yaml yaml = new Yaml(new Constructor(SpeedTestConfig.class));
    SpeedTestConfig config;//w w  w . ja v a2s.co  m
    FileInputStream inStream = new FileInputStream(configFilename);
    try {
        config = (SpeedTestConfig) yaml.load(inStream);
        config.configFilename = configFilename;
    } finally {
        try {
            inStream.close();
        } catch (IOException e) {
            logger.error("exception while closing config file", e);
        }
    }

    return config;
}

From source file:Main.java

public static void openNamedFile(String filename) {
    try {/*w  w  w .  j ava2 s  .  c  om*/
        File f = new File(filename);
        //   Log.e("kuinfa", "filename= " + filename);
        FileInputStream fis = new FileInputStream(f);

        long size = f.length();
        name = f.getName();
        patch = f.getParentFile().toString();
        DataInputStream dis = new DataInputStream(fis);
        byte[] b = new byte[(int) size];
        int length = dis.read(b, 0, (int) size);

        dis.close();
        fis.close();

        String ttt = new String(b, 0, length, "UTF-8");

        try {
            ttt = new String(ttt.getBytes(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }

    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
}

From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.AbstractSslContext.java

protected static TrustManager[] createTrustManager(JSONObject sslConf) {
    TrustManager[] tms = null;/*w  ww .j av a2s  .  com*/
    try {

        String TRUST_STORE = "etc/conf/trust.jks";
        String TRUST_STORE_PASSWORD = "Changeme_123";
        String TRUST_STORE_TYPE = "jks";
        if (sslConf != null) {
            TRUST_STORE = sslConf.getString("trustStore");
            TRUST_STORE_PASSWORD = sslConf.getString("trustStorePass");
            TRUST_STORE_TYPE = sslConf.getString("trustStoreType");
        }
        FileInputStream f_trustStore = new FileInputStream(TRUST_STORE);
        KeyStore ks = KeyStore.getInstance(TRUST_STORE_TYPE);
        ks.load(f_trustStore, TRUST_STORE_PASSWORD.toCharArray());
        f_trustStore.close();

        String alg = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmFact = TrustManagerFactory.getInstance(alg);
        tmFact.init(ks);
        tms = tmFact.getTrustManagers();

    } catch (Exception e) {
        LOG.error("create TrustManager fail!", e);
    }
    return tms;
}

From source file:edu.smc.mediacommons.modules.Md5Module.java

public static String getMD5(File file) {
    String md5 = null;/*from   www . ja va2s .c  o m*/
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(file);
        md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return md5;
}