Java InputStream to String inputStreamToString(InputStream is)

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

Description

Utility method for helping with JXTA messages.

License

Apache License

Declaration

public static String inputStreamToString(InputStream is)
        throws IOException 

Method Source Code

//package com.java2s;
/* Copyright 2014 MITRE Corporation
 *
 * 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./*from   www .j  a  v  a  2  s  .  com*/
 */

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**
     * Utility method for helping with JXTA messages.  Take an input stream, and return its entire contents as a string.
     * Don't do this for very large input streams, because it's all in memory.
     * @deprecated
     */
    public static String inputStreamToString(InputStream is)
            throws IOException {
        final byte[] buffer = new byte[0x10000];
        StringBuilder out = new StringBuilder();

        int read;
        do {
            read = is.read(buffer, 0, buffer.length);
            if (read > 0) {
                out.append(new String(buffer, 0, read));
            }
        } while (read >= 0);

        return out.toString();
    }
}

Related

  1. inputStreamToString(InputStream inputStream)
  2. inputStreamToString(InputStream inputStream)
  3. inputStreamToString(InputStream inputStream)
  4. inputStreamToString(InputStream inputStream)
  5. inputStreamToString(InputStream inputStream, String charsetName)
  6. inputStreamToString(InputStream is)
  7. inputStreamToString(InputStream is)
  8. inputStreamToString(InputStream is)
  9. inputStreamToString(InputStream is)