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:Main.java

private static void closeQuietly(InputStream is) {
    if (is != null) {
        try {/*  ww w  .j  a  va 2 s  .c  o m*/
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static Bitmap getImageFromAssetsFile(Context ct, String fileName) {
    Bitmap image = null;//ww w . j a v  a 2 s.co  m
    AssetManager am = ct.getAssets();
    try {
        InputStream is = am.open(fileName);
        image = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return image;

}

From source file:Main.java

private static Properties loadPropties(Context context, String file) throws IOException {
    Properties properties = new Properties();
    try {//from w  ww .jav  a2s. c  om
        InputStream fileStream = context.getAssets().open(file);
        properties.load(fileStream);
        fileStream.close();
    } catch (FileNotFoundException e) {
    }
    return properties;
}

From source file:Main.java

/**
 * get bitmap from assert//from ww w  . j  a v  a2 s . c  om
 * 
 * @param context
 * @param fileName
 * @return
 */
public static Bitmap getImageFromAssetFile(Context context, String fileName) {
    Bitmap image = null;
    try {
        AssetManager am = context.getAssets();
        InputStream is = am.open(fileName);
        image = BitmapFactory.decodeStream(is);
        is.close();
    } catch (Exception e) {

    }
    return image;
}

From source file:edu.lternet.pasta.datapackagemanager.checksum.DigestUtilsWrapper.java

/**
 * Gets the SHA-1 checksum of a file object 
 * //from  www  . j  a  v  a2  s.com
 * @param file  the file object whose checksum is being calculated
 * @return the SHA-1 checksum, a 40-character string
 * @throws Exception
 */
public static String getSHA1Checksum(File file) throws Exception {
    InputStream fis = new FileInputStream(file);
    String shaHex = DigestUtils.shaHex(fis);
    fis.close();
    return shaHex;
}

From source file:Main.java

private static void silentClose(InputStream input) {
    try {/*from   w  w w  .j a v a 2 s  . c  o m*/
        if (input != null) {
            input.close();
        }
    } catch (Exception error) {
        //should never happen
    } finally {
    }
}

From source file:Main.java

public static Bitmap getAssetBitmap(Context context, String path) {
    Bitmap mBitmap = null;//from ww  w.j ava 2s. c  om
    try {
        InputStream is = context.getAssets().open(path);
        mBitmap = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mBitmap;
}

From source file:Main.java

public static Bitmap fetchImage(String fileUrl) {
    try {//w ww  .jav a2  s .  c  o  m
        URL myFileUrl = new URL(fileUrl);
        HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        Bitmap image = BitmapFactory.decodeStream(is);
        is.close();
        return image;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:io.encoded.jersik.runtime.client.AbstractServiceClient.java

private static void consume(HttpEntity entity) throws IOException {
    if (entity != null && entity.isStreaming()) {
        InputStream in = entity.getContent();
        if (in != null)
            in.close();
    }/*from w ww.  j  a va  2s  . c  o m*/
}

From source file:Main.java

/**
 * Close the specified input stream, ignoring any exceptions.
 *//*from  w ww  .j  av a  2 s .c  o m*/
public static void closeQuietly(InputStream inputStream) {
    try {
        inputStream.close();
    } catch (final Exception e) {
        // Ignored
    }
}