added getContent method to IOUtil

This commit is contained in:
Sebastian Sdorra
2011-09-30 08:30:14 +02:00
parent 219af68563
commit a092d6b79f
2 changed files with 48 additions and 30 deletions

View File

@@ -45,12 +45,14 @@ import sonia.scm.io.ZipUnArchiver;
//~--- JDK imports ------------------------------------------------------------
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
@@ -592,6 +594,48 @@ public class IOUtil
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param in
*
* @return
* @since 1.8
*
* @throws IOException
*/
public static String getContent(InputStream in) throws IOException
{
StringBuilder content = new StringBuilder();
BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(in));
String s = System.getProperty("line.separator");
String line = reader.readLine();
while (line != null)
{
content.append(line);
line = reader.readLine();
if (line != null)
{
content.append(s);
}
}
}
finally
{
close(reader);
}
return content.toString();
}
/**
* Method description
*

View File

@@ -396,42 +396,16 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
*/
private void processErrorStream(InputStream in) throws IOException
{
BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder error = new StringBuilder();
String s = System.getProperty("line.separator");
String line = reader.readLine();
while (line != null)
{
error.append(line);
line = reader.readLine();
if (line != null)
{
error.append(s);
}
}
if (logger.isWarnEnabled())
{
String msg = error.toString().trim();
String error = IOUtil.getContent(in);
if (Util.isNotEmpty(msg))
if (Util.isNotEmpty(error))
{
logger.warn(msg);
logger.warn(error.trim());
}
}
}
finally
{
IOUtil.close(reader);
}
}
/**
* Method description