Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.Blob


            includedContentPartList = new ArrayList<Map.Entry<UriRef,Blob>>();
            Set<String> ignoreContentPartUris = getIgnoredContentURIs(properties);
            nextContentPartEntry:
            for(Entry<UriRef,Blob> entry : getContentParts(ci,Blob.class).entrySet()){
                if(!ignoreContentPartUris.contains(entry.getKey().getUnicodeString())){
                    Blob blob = entry.getValue();
                    MediaType blobMediaType = MediaType.valueOf(blob.getMimeType());
                    for(MediaType included : includeMediaTypes) {
                        if(blobMediaType.isCompatible(included)){
                            includedContentPartList.add(entry);
                            continue nextContentPartEntry;
                        }
View Full Code Here


        createBlob(createContentSource("text/;charset=UTF-8"));
    }
   
    @Test
    public void testMimeType() 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"));
    }
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
    @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"));
    }
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("other"));
        Assert.assertEquals("test", blob.getParameter().get("other"));
    }
    @Test
    public void testIllegalFormatedParameter() throws IOException {
        Blob blob = createBlob(createContentSource("text/plain;=UTF-8"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
       
        blob = createBlob(createContentSource("text/plain;charset=UTF-8;=illegal"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = createBlob(createContentSource("text/plain;=illegal;charset=UTF-8"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = createBlob(createContentSource("text/plain;charset="));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
        blob = createBlob(createContentSource("text/plain;charset"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
       
        blob = createBlob(createContentSource("text/plain;charset=UTF-8;test="));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));

        blob = createBlob(createContentSource("text/plain;charset=UTF-8;test"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
   
        blob = createBlob(createContentSource("text/plain;test;charset=UTF-8;"));
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertEquals(blob.getParameter().size(),1);
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
    }
View Full Code Here

        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
    }
    @Test(expected=UnsupportedOperationException.class)
    public void testReadOnlyParameter() throws IOException {
        Blob blob = createBlob(createContentSource("text/plain;test;charset=UTF-8"));
        blob.getParameter().put("test", "dummy");
    }
View Full Code Here

    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);
    }
View Full Code Here

    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());
    }
View Full Code Here

     * 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());
    }
View Full Code Here

            do {
                try {
                    cpUri = ci.getPartUri(index);
                    index++;
                    try {
                        Blob blob = ci.getPart(cpUri, Blob.class);
                        if(mimeTypes.contains(blob.getMimeType().toLowerCase())){
                            return Collections.singletonMap(cpUri, blob)
                                    .entrySet().iterator().next();
                        } // else no match
                    } catch (ClassCastException e) {
                        // not a Blob -> ignore!
View Full Code Here

                        id,content.getContentType());
                    contentItem = ciFactory.createContentItem(id,
                        new StreamSource(fis.openStream(),fis.getContentType()),
                        metadata);
                } else {
                    Blob blob = ciFactory.createBlob(new StreamSource(fis.openStream(), fis.getContentType()));
                    UriRef contentPartId = null;
                    if(fis.getFieldName() != null && !fis.getFieldName().isEmpty()){
                        contentPartId = new UriRef(fis.getFieldName());
                    } else {
                        //generating a random ID might break metadata
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.