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:fm.last.musicbrainz.coverart.util.HttpUtil.java

/**
 * Ensures that the entity content is fully consumed and the content stream, if exists, is closed.<br/>
 * <br/>/*from w  w w  . j  a v  a2  s.  com*/
 * This method is copied from Apache HttpClient version 4.1 {@link EntityUtils#consume(HttpEntity)}, in order to keep
 * compatibility with lower HttpClient versions, such as the "pre-BETA snapshot" used in android.
 *
 * @param entity
 * @throws IOException if an error occurs reading the input stream
 * @since 4.1
 */
public static void consumeEntity(final HttpEntity entity) throws IOException {
    if (entity == null) {
        return;
    }
    if (entity.isStreaming()) {
        InputStream instream = entity.getContent();
        if (instream != null) {
            instream.close();
        }
    }
}

From source file:uk.ac.aber.dcs.cs22120.group16.utilities.ClientMultipartFormPost.java

public static void consume(final HttpEntity entity) throws IOException {
    if (entity == null) {
        return;/*  ww  w. j a va2  s  .  c o  m*/
    }
    if (entity.isStreaming()) {
        InputStream instream = entity.getContent();
        if (instream != null) {
            instream.close();
        }
    }
}

From source file:Main.java

public static Bitmap getBitMap(String url) {
    URL myFileUrl = null;/*  ww w.  j  a va  2  s .co m*/
    Bitmap bitmap = null;
    try {
        myFileUrl = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        bitmap = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static String getStringFromFile(Resources resources, String filePath) {
    try {//from   w w w. ja v  a2  s . co  m
        InputStream is = resources.getAssets().open(filePath);
        String ret = convertStreamToString(is);
        is.close();
        return ret;
    } catch (IOException e) {
        throw new RuntimeException("unable to load asset " + filePath);
    }
}

From source file:Main.java

public static Bitmap getHttpBitmap(String url) {
    URL myFileUrl = null;/*from   www .j  a  v a 2 s .c om*/
    Bitmap bitmap = null;
    try {
        myFileUrl = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
        conn.setConnectTimeout(0);
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        bitmap = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static void closeQuietly(InputStream is) {
    if (is == null)
        return;//from  w ww  .  ja v  a  2  s.  c o m

    try {
        is.close();
    } catch (Exception e) {
    }
}

From source file:Main.java

public static Bitmap returnBitMap(String url) {
    URL myFileUrl = null;// w  w w .  java2s  .co  m
    Bitmap bitmap = null;
    try {
        myFileUrl = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        bitmap = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Log.v(tag, bitmap.toString());

    return bitmap;
}

From source file:Main.java

private static void closeQuietly(InputStream input) {
    try {//from w ww  . ja va  2s .  c  o  m
        if (input != null) {
            input.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

From source file:Main.java

public static void close(InputStream in) {
    if (in != null) {
        try {/*  w w w .j  av a  2 s . c om*/
            in.close();
        } catch (IOException e) {
            closingFailed(e);
        }
    }
}

From source file:Main.java

public static String AssetJSONFile(String filename, Context context) throws IOException {
    AssetManager manager = context.getAssets();
    InputStream file = manager.open(filename);
    byte[] formArray = new byte[file.available()];
    file.read(formArray);/*from w  ww . jav a2s . com*/
    file.close();

    return new String(formArray);
}