use of org.apache.stanbol.enhancer.servicesapi.Blob 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.Blob 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.Blob in project stanbol by apache.
the class BlobTest method testMultipleSeparators.
@Test
public void testMultipleSeparators() throws IOException {
Blob blob = createBlob(createContentSource("text/plain;;charset=UTF-8"));
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
blob = createBlob(createContentSource("text/plain;charset=UTF-8;;other=test"));
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
Assert.assertTrue(blob.getParameter().containsKey("other"));
Assert.assertEquals("test", blob.getParameter().get("other"));
}
use of org.apache.stanbol.enhancer.servicesapi.Blob in project stanbol by apache.
the class BlobTest method testString.
/**
* Tests correct handling of UTF-8 as default charset
* @throws IOException
*/
@Test
public void testString() throws IOException {
String test = "Exámplê";
//first via a StringSource
ContentSource cs = new StringSource(test);
Blob blob = createBlob(cs);
Assert.assertEquals("text/plain", blob.getMimeType());
Assert.assertTrue(blob.getParameter().containsKey("charset"));
Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
String value = new String(IOUtils.toByteArray(blob.getStream()), UTF8);
Assert.assertEquals(test, value);
}
Aggregations