use of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource in project stanbol by apache.
the class BlobTest method testDefaultBinaryMimeType.
/**
* Tests the default mimeType "application/octet-stream" for binary data.
* @throws IOException
*/
@Test
public void testDefaultBinaryMimeType() throws IOException {
Blob blob = createBlob(new ByteArraySource("dummy".getBytes(UTF8)));
Assert.assertEquals("application/octet-stream", blob.getMimeType());
Assert.assertTrue(blob.getParameter().isEmpty());
blob = createBlob(new StreamSource(new ByteArrayInputStream("dummy".getBytes(UTF8))));
Assert.assertEquals("application/octet-stream", blob.getMimeType());
Assert.assertTrue(blob.getParameter().isEmpty());
}
use of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource in project stanbol by apache.
the class BlobTest method testStringWithCustomCharset.
/**
* This tests that texts with custom charsets are converted to UTF-8.
* @throws IOException
*/
@Test
public void testStringWithCustomCharset() throws IOException {
String test = "Exámplê";
Charset ISO8859_4 = Charset.forName("ISO-8859-4");
// first via a StringSource
ContentSource cs = new StringSource(test, ISO8859_4, "text/plain");
Blob blob = createBlob(cs);
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset"));
// 2nd via a ByteArray
byte[] data = test.getBytes(ISO8859_4);
cs = new ByteArraySource(data, "text/plain; charset=" + ISO8859_4.name());
blob = createBlob(cs);
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset"));
// 3rd as Stream
cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; charset=" + ISO8859_4.name());
blob = createBlob(cs);
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals(ISO8859_4.name(), blob.getParameter().get("charset"));
cs = new StreamSource(new ByteArrayInputStream(data), "text/plain; " + ISO8859_4.name());
}
use of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource in project stanbol by apache.
the class ContentSourceTest method checkDataFromStreamSource.
@Test
public void checkDataFromStreamSource() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
Assert.assertTrue(Arrays.equals(DATA, source.getData()));
// multiple calls must work
source.getData();
}
use of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource in project stanbol by apache.
the class ContentSourceTest method checkStreamFromStreamSource.
/*
* Tests checking correct handling of data
*/
@Test
public void checkStreamFromStreamSource() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
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);
}
}
use of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource in project stanbol by apache.
the class ContentSourceTest method checkFileName.
@Test
public void checkFileName() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA), null, null, null);
assertNull(source.getFileName());
source = new StreamSource(new ByteArrayInputStream(DATA), null, FILE_NAME, null);
assertEquals(FILE_NAME, source.getFileName());
source = new ByteArraySource(DATA, null, FILE_NAME);
assertEquals(FILE_NAME, source.getFileName());
source = new ByteArraySource(DATA, null, FILE_NAME, null);
assertEquals(FILE_NAME, source.getFileName());
}
Aggregations