Here you can find the source of inputStreamToText(InputStream inputStream)
public static String inputStreamToText(InputStream inputStream) throws IOException
//package com.java2s; /**/*from ww w . ja va 2 s . c o m*/ * Copyright 2003-2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Converts a response in an InputStream to a String for easy comparisons */ public static String inputStreamToText(InputStream inputStream) throws IOException { byte[] bytes = inputStreamToBytes(inputStream); return new String(bytes); } /** * Converts a response in an InputStream to a byte[] for easy manipulation */ public static byte[] inputStreamToBytes(InputStream inputStream) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[10000]; int r; while ((r = inputStream.read(buffer)) != -1) { byteArrayOutputStream.write(buffer, 0, r); } return byteArrayOutputStream.toByteArray(); } }