Examples of ByteArraySource


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

        source.getData();
    }

    @Test
    public void checkStreamFromByteArraySource() throws IOException {
        ContentSource source = new ByteArraySource(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

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

            Assert.assertTrue(e instanceof IllegalStateException);
        }
    }
    @Test
    public void checkDataFromByteArraySource() throws IOException {
        ContentSource source = new ByteArraySource(DATA);
        assertTrue(Arrays.equals(DATA, source.getData()));
        //also check that the array is not copied
        //Also checks multiple calls to getData MUST work
        assertSame(DATA, source.getData());
    }
View Full Code Here

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

        Assert.assertTrue(Arrays.equals(iso8859_4_data, out.toByteArray()));
       
    }
    @Test
    public void checkDataFromStringSource() throws IOException {
        ContentSource source = new ByteArraySource(DATA);
        Assert.assertTrue(Arrays.equals(DATA, source.getData()));
        //multiple calls must work
        source.getData();
    }
View Full Code Here

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

        InputStream in = getTestResource("content.html");
        assertNotNull("HTML content not found",in);
        byte[] htmlData = IOUtils.toByteArray(in);
        IOUtils.closeQuietly(in);
        ci = ciFactory.createContentItem(contentItemId,
            new ByteArraySource(htmlData, "text/html; charset=UTF-8"));
        htmlContent = new String(htmlData, UTF8);
        //create a Blob with the text content
        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"),
            ciFactory.createBlob(new ByteArraySource(textData, "text/plain; charset=UTF-8")));
        textContent = new String(textData, UTF8);
        //add the metadata
        ci.getMetadata().addAll(rdfData);
    }
View Full Code Here

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

    @Test
    public void testContentWithAdditionalMetadata() throws IOException, LDPathParseException {
        byte[] content = "text content".getBytes();
        UriRef uri = ContentItemHelper.makeDefaultUrn(content);

        ContentItem contentItem = ciFactory.createContentItem(uri, new ByteArraySource(content,
                "text/plain; charset=UTF-8"));

        TripleCollection tc = new SimpleMGraph();
        TypedLiteral literal = LiteralFactory.getInstance().createTypedLiteral("Michael Jackson");
        UriRef subject = new UriRef("dummyUri");
View Full Code Here

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

        source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM,FILE_NAME,HEADERS);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
    }
    @Test
    public void checkMediaTypeForByteArraySource() throws IOException {
        ContentSource source = new ByteArraySource(DATA);
        assertEquals(DEFAULT_MT, source.getMediaType());
        source = new ByteArraySource(DATA,null);
        assertEquals(DEFAULT_MT, source.getMediaType());
        source = new ByteArraySource(DATA,null,FILE_NAME,HEADERS);
        assertEquals(DEFAULT_MT, source.getMediaType());
       
        source = new ByteArraySource(DATA,MT);
        assertEquals(MT, source.getMediaType());
        source = new ByteArraySource(DATA,MT,FILE_NAME,HEADERS);
        assertEquals(MT, source.getMediaType());
        //Parameters MUST BE preserved!
        source = new ByteArraySource(DATA,MT_WITH_PARAM);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
        source = new ByteArraySource(DATA,MT_WITH_PARAM,FILE_NAME);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
        source = new ByteArraySource(DATA,MT_WITH_PARAM,FILE_NAME,HEADERS);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
    }
View Full Code Here

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

        assertNull(source.getFileName());

        source = new StreamSource(new ByteArrayInputStream(DATA),null,FILE_NAME,null);
        assertEquals(FILE_NAME, source.getFileName());
       
        source = new ByteArraySource(DATA,null,FILE_NAME);
        assertEquals(FILE_NAME, source.getFileName());
       
        source = new ByteArraySource(DATA,null,FILE_NAME,null);
        assertEquals(FILE_NAME, source.getFileName());
       
    }
View Full Code Here

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

        assertNotNull(source.getHeaders());
        assertTrue(source.getHeaders().isEmpty());
        source = new StreamSource(new ByteArrayInputStream(DATA),null,null,HEADERS);
        assertEquals(HEADERS, source.getHeaders());
       
        source = new ByteArraySource(DATA,null,null,null);
        assertNotNull(source.getHeaders());
        assertTrue(source.getHeaders().isEmpty());
        source = new ByteArraySource(DATA,null,null,HEADERS);
        assertEquals(HEADERS, source.getHeaders());
    }
View Full Code Here

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

        InputStream in = getTestResource("example.txt");
        assertNotNull("Example Plain text content not found",in);
        byte[] textData = IOUtils.toByteArray(in);
        IOUtils.closeQuietly(in);
        ci = ciFactory.createContentItem(contentItemId,
            new ByteArraySource(textData, "text/html; charset=UTF-8"));
        ci.getMetadata().addAll(rdfData);
    }
View Full Code Here

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

        }
        log.debug("Created ContentItem with id:{} and uri:{}", id, uri);
        final MGraph g = new IndexedMGraph();
        ContentItem ci = null;
        try {
            ci = ciFactory.createContentItem(uri, new ByteArraySource(content, contentType), g);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", uri.getUnicodeString());
            throw new StoreException(String.format("Failed to create contentitem with uri: %s",
                uri.getUnicodeString()));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.