use of java.io.BufferedReader in project camel by apache.
the class IOHelper method loadText.
/**
* Loads the entire stream into memory as a String and returns it.
* <p/>
* <b>Notice:</b> This implementation appends a <tt>\n</tt> as line
* terminator at the of the text.
* <p/>
* Warning, don't use for crazy big streams :)
*/
public static String loadText(InputStream in) throws IOException {
StringBuilder builder = new StringBuilder();
InputStreamReader isr = new InputStreamReader(in);
try {
BufferedReader reader = buffered(isr);
while (true) {
String line = reader.readLine();
if (line != null) {
builder.append(line);
builder.append("\n");
} else {
break;
}
}
return builder.toString();
} finally {
close(isr, in);
}
}
use of java.io.BufferedReader in project camel by apache.
the class IOConverterTest method testStringByBufferedReader.
public void testStringByBufferedReader() throws Exception {
BufferedReader br = IOHelper.buffered(new StringReader("Hello World"));
assertEquals("Hello World", IOConverter.toString(br));
}
use of java.io.BufferedReader in project camel by apache.
the class IOConverterTest method testToStringBufferReader.
public void testToStringBufferReader() throws Exception {
BufferedReader br = IOHelper.buffered(new StringReader("Hello World"));
String s = IOConverter.toString(br);
assertNotNull(s);
assertEquals("Hello World", s);
}
use of java.io.BufferedReader in project camel by apache.
the class IOConverterCharsetTest method testToReaderFileWithCharsetLatin1.
public void testToReaderFileWithCharsetLatin1() throws Exception {
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
BufferedReader reader = IOConverter.toReader(file, "ISO-8859-1");
BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1"));
try {
String line = reader.readLine();
String naiveLine = naiveReader.readLine();
assertEquals(naiveLine, line);
assertEquals(CONTENT, line);
} finally {
reader.close();
naiveReader.close();
}
}
use of java.io.BufferedReader in project camel by apache.
the class IOConverterCharsetTest method testToInputStreamFileWithCharsetUTF8.
public void testToInputStreamFileWithCharsetUTF8() throws Exception {
switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
InputStream in = IOConverter.toInputStream(file, "UTF-8");
// do read with default charset!
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
try {
String line = reader.readLine();
String naiveLine = naiveReader.readLine();
assertEquals(naiveLine, line);
assertEquals(CONTENT, line);
} finally {
reader.close();
naiveReader.close();
}
}
Aggregations