Package org.apache.stanbol.enhancer.servicesapi.helper

Examples of org.apache.stanbol.enhancer.servicesapi.helper.InMemoryBlob


     * Override to test InMemoryBlob instead of AbstractBlob
     * @see org.apache.stanbol.enhancer.serviceapi.helper.BlobMimeTypeHandlingTest#getBlobToTestMimetypeHandling(java.lang.String)
     */
    @Override
    protected Blob getBlobToTestMimetypeHandling(String mimeType) {
        return new InMemoryBlob("dummy".getBytes(UTF8), mimeType);
    }
View Full Code Here


     * @throws IOException
     */
    @Test
    public void testString() throws IOException{
        String test = "Exámplê";
        Blob blob = new InMemoryBlob(test, null);
        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

     * @throws IOException
     */
    @Test
    public void testStringWithCharset() throws IOException{
        String test = "Exámplê";
        Blob blob = new InMemoryBlob(test, "text/plain;charset=ISO-8859-4");
        Assert.assertEquals("text/plain", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().containsKey("charset"));
        Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
    }
View Full Code Here

     * Tests the default mimeType "application/octet-stream" for binary data.
     * @throws IOException
     */
    @Test
    public void testDefaultBinaryMimeType() throws IOException {
        Blob blob = new InMemoryBlob("dummy".getBytes(UTF8), null);
        Assert.assertEquals("application/octet-stream", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());

        blob = new InMemoryBlob(new ByteArrayInputStream("dummy".getBytes(UTF8)), null);
        Assert.assertEquals("application/octet-stream", blob.getMimeType());
        Assert.assertTrue(blob.getParameter().isEmpty());
    }
View Full Code Here

                        id,content.getContentType());
                    contentItem = new InMemoryContentItem(id,
                        IOUtils.toByteArray(fis.openStream()),
                        fis.getContentType(), metadata);
                } else {
                    Blob blob = new InMemoryBlob(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

                               byte[] content,
                               String mimeType,
                               MGraph metadata,
                               Map<String,List<Object>> constraints) {
        super(id == null ? ContentItemHelper.makeDefaultUri(CONTENT_ITEM_URI_PREFIX, content) : new UriRef(
                ContentItemIDOrganizer.attachBaseURI(id)), new InMemoryBlob(content, mimeType),
                metadata == null ? new SimpleMGraph() : metadata);

        if (metadata == null) {
            metadata = new SimpleMGraph();
        }
View Full Code Here

            "<html>\n" +
            "  <body>\n" +
            "    This is a <b>ContentItem</b> to <i>Mime Multipart</i> test!\n" +
            "  </body>\n" +
            "</html>","text/html");
        contentItem.addPart(new UriRef("run:text:text"), new InMemoryBlob(
            "This is a ContentItem to Mime Multipart test!", "text/plain"));
        contentItem.getMetadata().add(new TripleImpl(
            new UriRef("urn:test"), RDF.type, new UriRef("urn:types:Document")));
        //mark the main content as parsed and also that all
        //contents and contentparts should be included
View Full Code Here

                log.debug("Plain Content: \n{}",writer.toString());
            }
            String random = randomUUID().toString();
            UriRef textBlobUri = new UriRef("urn:tika:text:"+random);
            ci.addPart(textBlobUri,
                new InMemoryBlob(writer.toString(),
                    TEXT_PLAIN.toString())); //string -> no encoding
            if(xhtmlHandler != null){
                if(log.isDebugEnabled()){
                    log.debug("XML Content: \n{}",xhtmlHandler.toString());
                }
                UriRef xhtmlBlobUri = new UriRef("urn:tika:xhtml:"+random);
                ci.addPart(xhtmlBlobUri,
                    new InMemoryBlob(xhtmlHandler.toString(),
                        "application/xhtml+xml")); //string -> no encoding
            }
            //add the extracted metadata
            if(log.isDebugEnabled()){
                for(String name : metadata.names()){
View Full Code Here

        in = getTestResource("content.txt");
        byte[] textData = IOUtils.toByteArray(in);
        IOUtils.closeQuietly(in);
        assertNotNull("Plain text content not found",in);
        ci.addPart(new UriRef(ci.getUri().getUnicodeString()+"_text"),
            new InMemoryBlob(textData, "text/plain; charset=UTF-8"));
        textContent = new String(textData, UTF8);
        //add the metadata
        ci.getMetadata().addAll(rdfData);
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.helper.InMemoryBlob

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.