Example usage for java.io InputStream close

List of usage examples for java.io InputStream close

Introduction

In this page you can find the example usage for java.io InputStream 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:com.buschmais.maexo.test.Constants.java

/**
 * Load properties file and ignore any exceptions.
 * //from  w  w  w.j  a v a2 s .  co  m
 * @param classpath resource name
 * @return properties loaded from classpath resource
 */
private static Properties getPropertiesFrom(String string) {
    Properties result = new Properties();
    try {
        InputStream stream = Constants.class.getResourceAsStream("/version.properties");
        try {
            result.load(stream);
        } finally {
            stream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:cn.mdict.utils.IOUtil.java

public static void forceClose(InputStream is) {
    try {//w  ww.j  a  v a 2  s  .com
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:br.com.riselabs.cotonet.model.db.Database.java

public static Connection getConnection() {
    Thread currentThread = Thread.currentThread();
    ClassLoader classloader = currentThread.getContextClassLoader();
    InputStream input = classloader.getResourceAsStream("db.properties");
    Properties prop = new Properties();
    try {//from   w  ww .j a v a2 s .c om
        if (input != null) {
            prop.load(input);
            input.close();
        } else {
            Logger.logStackTrace(new FileNotFoundException("The file 'db.properties was not found."));
        }
    } catch (IOException e) {
        Logger.logStackTrace(e);
    }
    String db = prop.getProperty("database.name");
    String user = prop.getProperty("database.user");
    String pass = prop.getProperty("database.password");
    return getConnection(db, user, pass);
}

From source file:Main.java

public static void copyStream(InputStream in, OutputStream out) {
    try {/*from  w  w w  .j  av a 2  s . c  o  m*/
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();

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

From source file:Main.java

public static Document loadXML(String xml) {
    if (null == xml) {
        return null;
    }//from   ww w  .j av a  2s  .  c o m
    Document dom = null;
    InputStream stream = null;
    try {
        stream = new ByteArrayInputStream(xml.getBytes("utf-8"));
        return load(stream);
    } catch (Exception e) {
    } finally {
        try {
            stream.close();
        } catch (Exception e) {

        }
    }
    return dom;
}

From source file:Main.java

private static void copyInputStreamToFile(InputStream is, File file) throws Exception {
    int bytes;//from  ww w.j  ava 2s .c o  m
    byte[] buf = new byte[BUFFER_SIZE];

    FileOutputStream fos = new FileOutputStream(file);
    while ((bytes = is.read(buf, 0, BUFFER_SIZE)) > 0) {
        fos.write(buf, 0, bytes);
    }

    is.close();
    fos.close();
}

From source file:flink.iso8583.parse.ConfigParser.java

/** Creates a message factory from the file located at the specified URL. */
public static MessageFactory createFromUrl(URL url) throws IOException {
    MessageFactory mfact = new MessageFactory();
    InputStream stream = url.openStream();
    try {//from w w w  . j  a  va  2s . com
        parse(mfact, stream);
    } finally {
        stream.close();
    }
    return mfact;
}

From source file:com.founder.fix.fixflow.I18N.PropertiesUtil.java

/**
 * ?/* w ww  .j a  va2 s  . co m*/
 * @param path 
 * @return ?
 */
public static Properties load(String path) {
    Properties prop = null;
    try {
        InputStream is = null;
        is = PropertiesUtil.class.getClassLoader().getResourceAsStream(path);
        prop = new Properties();

        prop.load(is);
        is.close();
        propsMap.put(path, prop);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return prop;
}

From source file:com.aqnote.shared.cryptology.cert.loader.CaCertLoader.java

public synchronized static X509Certificate getRootCaCert() throws IOException {
    if (rootCaCert == null) {
        ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
        InputStream is = classLoader.getResourceAsStream(CA_Cert_FILE);
        rootCaCert = PKCSReader.readCert(is);
        is.close();
    }/*w  w  w  . j a  v  a 2 s  . c om*/
    return rootCaCert;
}

From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java

public synchronized static X509Certificate getCaCrt() throws IOException {
    if (caCrt == null) {
        ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
        InputStream is = classLoader.getResourceAsStream(CA_CRT_FILE);
        caCrt = PKCSReader.readCert(is);
        is.close();
    }/*  w  w  w  .  java 2  s.c o  m*/
    return caCrt;
}