Description
Populate a StringBuffer with the contents of an InputStream
License
Open Source License
Parameter
Parameter | Description |
---|
out | InputStream to process |
Exception
Parameter | Description |
---|
IOException | an exception |
Return
StringBuffer object containing InputStream contents
Declaration
public static StringBuffer getInputStreamString(final InputStream in) throws Exception
Method Source Code
//package com.java2s;
/**//from w w w.j a v a 2s. c o m
* Utility program to handle SSH Connection to ESXi hosts, running commands,
* on VMware ESXi host
*
* Copyright (c) 2016
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* @author VMware
* @author Gururaja Hegdal (ghegdal@vmware.com)
* @version 1.0
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Main {
/**
* Populate a StringBuffer with the contents of an InputStream
*
* @param out InputStream to process
* @return StringBuffer object containing InputStream contents
* @throws IOException
*/
public static StringBuffer getInputStreamString(final InputStream in) throws Exception {
StringBuffer out = null;
if (in != null) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try {
out = new StringBuffer();
String tmp = "";
while ((tmp = reader.readLine()) != null) {
out.append(tmp + "\n");
}
} finally {
if (reader != null) {
reader.close();
}
}
} else {
System.err.println("InputStream parameter is null");
}
return out;
}
}
Related
- getInputStreamFromFile(final File file)
- getInputStreamFromZip(ZipInputStream zis, String filename)
- getInputStreamLength(InputStream in)
- getInputStreamReader(InputStream in, String charset)
- getInputStreamReaderAsResource(Class clazz, String fileName)
- getInputStreamToBytes(InputStream is)
- inputStreamReadBytesUntil(int endInd, InputStream is, byte[] buf, int off)
- inputStreamToList(InputStream stream)