Search in sources :

Example 41 with Blob

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());
}
Also used : Blob(org.apache.stanbol.enhancer.servicesapi.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(org.apache.stanbol.enhancer.servicesapi.impl.StreamSource) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 42 with Blob

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());
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(org.apache.stanbol.enhancer.servicesapi.impl.StreamSource) Charset(java.nio.charset.Charset) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 43 with Blob

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"));
}
Also used : Blob(org.apache.stanbol.enhancer.servicesapi.Blob) Test(org.junit.Test)

Example 44 with Blob

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);
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) Test(org.junit.Test)

Aggregations

Blob (org.apache.stanbol.enhancer.servicesapi.Blob)44 IRI (org.apache.clerezza.commons.rdf.IRI)36 Test (org.junit.Test)21 IOException (java.io.IOException)20 Graph (org.apache.clerezza.commons.rdf.Graph)17 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)15 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)15 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)15 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)14 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)11 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)11 SOAPException (javax.xml.soap.SOAPException)4 Language (org.apache.clerezza.commons.rdf.Language)4 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 MediaType (javax.ws.rs.core.MediaType)3 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)3 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)3 NoSuchPartException (org.apache.stanbol.enhancer.servicesapi.NoSuchPartException)3 StreamSource (org.apache.stanbol.enhancer.servicesapi.impl.StreamSource)3