Package org.apache.stanbol.enhancer.servicesapi.impl

Examples of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource


        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


    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

                throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
            }
        } else { //normal content
            ContentItemFactory ciFactory = getContentItemFactory();
            contentItem = ciFactory.createContentItem(contentItemId,
                new StreamSource(entityStream, mediaType.toString()));
            //add the URI of the main content
            parsedContentIds.add(contentItem.getPartUri(0).getUnicodeString());
        }
        //set the parsed contentIDs to the EnhancementProperties
        getEnhancementProperties(contentItem).put(PARSED_CONTENT_URIS,
View Full Code Here

                FileItemStream fis = contentPartIterator.next();
                if(contentItem == null){
                    log.debug("create ContentItem {} for content (type:{})",
                        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
                        //TODO maybe we should throw an exception instead
                        contentPartId = new UriRef("urn:contentpart:"+ randomUUID());
                    }
                    log.debug("  ... add Blob {} to ContentItem {} with content (type:{})",
                        new Object[]{contentPartId, id, fis.getContentType()});
                    contentItem.addPart(contentPartId, blob);
                    parsedContentParts.add(contentPartId.getUnicodeString());
                }
            }
        } else {
            log.debug("create ContentItem {} for content (type:{})",
                id,content.getContentType());
            contentItem = ciFactory.createContentItem(id,
                new StreamSource(content.openStream(),content.getContentType()),
                metadata);
        }
        //add the URI of the main content to the parsed contentParts
        parsedContentParts.add(contentItem.getPartUri(0).getUnicodeString());
        return contentItem;
View Full Code Here

    /*
     * Tests ensuring the IllegalArgumentExceptions if null is parsed as stream
     */
    @Test(expected=IllegalArgumentException.class)
    public void missingStream(){
        new StreamSource(null);
    }
View Full Code Here

    public void missingStream(){
        new StreamSource(null);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingStream1(){
        new StreamSource(null,MT);
    }
View Full Code Here

    public void missingStream1(){
        new StreamSource(null,MT);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingStream2(){
        new StreamSource(null,MT,FILE_NAME);
    }
View Full Code Here

    public void missingStream2(){
        new StreamSource(null,MT,FILE_NAME);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingStream3(){
        new StreamSource(null,MT,HEADERS);
    }
View Full Code Here

    public void missingStream3(){
        new StreamSource(null,MT,HEADERS);
    }
    @Test(expected=IllegalArgumentException.class)
    public void missingStream4(){
        new StreamSource(null,MT,FILE_NAME,HEADERS);
    }
View Full Code Here

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

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.impl.StreamSource

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.