blob: 7e839968f07de7f34d63f075af9157a012ceb366 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.externaltools.internal.ant.editor.support;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.eclipse.ant.ui.internal.model.AntUIPlugin;
import org.eclipse.core.resources.ResourcesPlugin;
public class TestUtils {
public static String getStreamContentAsString(InputStream inputStream) {
InputStreamReader reader;
try {
reader = new InputStreamReader(inputStream, ResourcesPlugin.getEncoding());
} catch (UnsupportedEncodingException e) {
AntUIPlugin.log(e);
return ""; //$NON-NLS-1$
}
BufferedReader tempBufferedReader = new BufferedReader(reader);
return getReaderContentAsString(tempBufferedReader);
}
protected static String getReaderContentAsString(BufferedReader tempBufferedReader) {
StringBuffer tempResult = new StringBuffer();
try {
String tempLine= tempBufferedReader.readLine();
while(tempLine != null) {
if(tempResult.length() != 0) {
tempResult.append("\n"); //$NON-NLS-1$
}
tempResult.append(tempLine);
tempLine = tempBufferedReader.readLine();
}
} catch (IOException e) {
AntUIPlugin.log(e);
return null;
}
return tempResult.toString();
}
}