Java InputStream to String inputStreamToString(InputStream in)

Here you can find the source of inputStreamToString(InputStream in)

Description

input Stream To String

License

Apache License

Declaration

public static String inputStreamToString(InputStream in) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.InputStream;

import java.util.logging.Logger;

public class Main {
    private static final Logger LOG = Logger.getLogger("Utils");

    public static String inputStreamToString(InputStream in) {
        StringBuffer out = new StringBuffer();
        byte[] b = new byte[8192];
        try {//from ww w .ja v a 2 s .  co  m
            for (int n; (n = in.read(b)) != -1;) {
                out.append(new String(b, 0, n));
            }
        } catch (Exception e) {
            LOG.severe(e.getMessage());
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                    LOG.severe(e.getMessage());
                }
            }
        }
        return out.toString();
    }
}

Related

  1. inputStreamToString(InputStream in)
  2. inputStreamToString(InputStream in)
  3. InputStreamTOString(InputStream in)
  4. inputStreamToString(InputStream in)
  5. inputStreamToString(InputStream in)
  6. InputStreamToString(InputStream in)
  7. InputStreamTOString(InputStream in)
  8. InputStreamToString(InputStream in, String charset)
  9. InputStreamTOString(InputStream in, String encoding)