Java InputStream to String getInputStreamAsString(final InputStream is, final String encoding)

Here you can find the source of getInputStreamAsString(final InputStream is, final String encoding)

Description

get Input Stream As String

License

Open Source License

Declaration

public static String getInputStreamAsString(final InputStream is, final String encoding) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   w  ww.  j  av  a  2  s  .  c  o  m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.InputStream;

import java.util.Scanner;

public class Main {
    public static String getInputStreamAsString(final InputStream is, final String encoding) {
        final Scanner s = new Scanner(is, encoding).useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }
}

Related

  1. asArrayString(InputStream response)
  2. getInputStreamAsString(InputStream inStream)
  3. getInputStreamAsString(InputStream stream)
  4. getInputStreamContent(InputStream i, String encoding)
  5. getInputStreamContent(InputStream inputStream)