Search in sources :

Example 26 with StringSource

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

Aggregations

StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)26 Test (org.junit.Test)14 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)13 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)13 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)12 IRI (org.apache.clerezza.commons.rdf.IRI)10 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 Graph (org.apache.clerezza.commons.rdf.Graph)4 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)4 Token (org.apache.stanbol.enhancer.nlp.model.Token)4 PosTag (org.apache.stanbol.enhancer.nlp.pos.PosTag)4 Charset (java.nio.charset.Charset)3 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)3 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)3 ContentSource (org.apache.stanbol.enhancer.servicesapi.ContentSource)3 BeforeClass (org.junit.BeforeClass)3 Chunk (org.apache.stanbol.enhancer.nlp.model.Chunk)2 Sentence (org.apache.stanbol.enhancer.nlp.model.Sentence)2 Value (org.apache.stanbol.enhancer.nlp.model.annotation.Value)2