public static String fromInputStream()

in src/main/java/com/microsoft/store/partnercenter/utils/StringHelper.java [21:62]


    public static String fromInputStream(InputStream is, String encoding)
    {
        BufferedReader bufferedReader;

        if (is == null)
        {
            return "";
        }

        try
        {
            bufferedReader = new BufferedReader(new InputStreamReader(is, encoding));
        }
        catch (UnsupportedEncodingException e)
        {
            throw new PartnerException("Incorrect character encoding", e);
        }

        StringBuilder stringBuilder = new StringBuilder();
        String newLine = System.getProperty("line.separator");
        String line;

        try
        {
            while ((line = bufferedReader.readLine()) != null)
            {
                stringBuilder.append(line);
                stringBuilder.append(newLine);
            }
        }
        catch (IOException e)
        {
            throw new PartnerException("Error trying to obtain the response content body", e);
        }
        finally 
        {
			try { if(bufferedReader != null) bufferedReader.close(); } catch (IOException ex) { throw new PartnerException("There was an issue closing the buffer reader.", ex); }
			try { if(is != null) is.close(); } catch (IOException ex) { throw new PartnerException("There was an issue closing the stream.", ex); }
        }

        return stringBuilder.toString();
    }