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 String readStream(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1024);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);/*from   ww  w  .  j a  v  a2s.  c om*/
    }
    in.close();
    return sb.toString();
}

From source file:Main.java

public static ArrayList<String> getListSite(String extractPath, String md5) {
    ArrayList<String> listSite = new ArrayList<>();

    StringBuilder reval = new StringBuilder();
    try {//  w  ww .java  2 s .  com
        InputStream in = new FileInputStream(extractPath + "/site_map_" + md5);
        byte[] buf = new byte[1024];
        int c = 0;
        while ((c = in.read(buf)) >= 0) {
            reval.append(new String(buf, 0, c));
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    String[] arrSite = reval.toString().split(";");
    Collections.addAll(listSite, arrSite);
    return listSite;
}

From source file:com.opendoorlogistics.studio.dialogs.AboutBoxDialog.java

private static String info(boolean showLicenses) {

    // Use own class loader to prevent problems when jar loaded by reflection
    InputStream is = AboutBoxDialog.class
            .getResourceAsStream(showLicenses ? "/resources/Licences.html" : "/resources/About.html");
    StringWriter writer = new StringWriter();
    try {//from w  w w  .  j a  v  a 2 s.  c  om
        IOUtils.copy(is, writer, Charsets.UTF_8);
        is.close();
    } catch (Throwable e) {
    }

    String s = writer.toString();

    s = replaceVersionNumberTags(s);
    return s;
}

From source file:Main.java

public static byte[] readInput(InputStream in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int len = 0;/*from  www.  ja v a  2s .  com*/
    byte[] buffer = new byte[1024];
    while ((len = in.read(buffer)) > 0) {
        out.write(buffer, 0, len);
    }
    out.close();
    in.close();
    return out.toByteArray();
}

From source file:com.core.ServerConnector.java

public static String post(String endpoint, Map<String, String> params) throws Exception {
    String result = null;/*from  w  w  w. ja v  a2 s  .com*/
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);
    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    HttpPost httppost = new HttpPost(endpoint);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        result = SystemUtil.convertStreamToString(instream);

        instream.close();
    }

    return result;
}

From source file:Main.java

public static Document getDomDocument(File xmlFile) throws Exception {
    InputStream in = new URL("file:///" + xmlFile.getAbsolutePath()).openStream();
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
    Document xmlDoc = docBuilder.parse(in);
    in.close();
    return xmlDoc;
}

From source file:com.github.harmanpa.jrecon.utils.Compression.java

public static byte[] decompress(byte[] data) throws IOException {
    InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data));
    ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
    int b;/*  w w w.ja  v  a  2  s. com*/
    while ((b = is.read()) > -1) {
        baos.write(b);
    }
    is.close();
    return baos.toByteArray();
}

From source file:com.github.rnewson.couchdb.lucene.Rhino.java

private static String loadResource(final String name) throws IOException {
    final InputStream in = Rhino.class.getClassLoader().getResourceAsStream(name);
    try {// www. j av  a2 s .c  o  m
        return IOUtils.toString(in, "UTF-8");
    } finally {
        in.close();
    }
}

From source file:net.sourceforge.jencrypt.lib.Utils.java

public static void closeQuietly(InputStream input) {
    try {//from   w  w  w.j ava2s . c o m
        if (input != null) {
            input.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

From source file:Main.java

public static String convertInputStreamToString(InputStream inputStream) throws IOException {
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    String line;/*from   w  ww.jav  a 2  s . c o m*/
    String result = "";
    while ((line = bufferedReader.readLine()) != null)
        result += line;

    inputStream.close();
    return result;

}