use of org.apache.stanbol.enhancer.servicesapi.impl.StringSource in project stanbol by apache.
the class ContentSourceTest method checkStreamFromStringSource.
@Test
public void checkStreamFromStringSource() throws IOException {
ContentSource source = new StringSource(TEST_STRING);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(source.getStream(), out);
Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
try {
source.getStream();
//multiple calls are supported -> is OK
} catch (RuntimeException e) {
//multiple calls are not supported -> illegal state
Assert.assertTrue(e instanceof IllegalStateException);
}
//test different encoding
Charset ISO8859_4 = Charset.forName("ISO-8859-4");
byte[] iso8859_4_data = TEST_STRING.getBytes(ISO8859_4);
source = new StringSource(TEST_STRING, ISO8859_4, null);
out = new ByteArrayOutputStream();
IOUtils.copy(source.getStream(), out);
Assert.assertTrue(Arrays.equals(iso8859_4_data, out.toByteArray()));
}
Aggregations