Package org.apache.stanbol.enhancer.servicesapi

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


            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


        assertSame(DATA, source.getData());
    }
   
    @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()));
       
    }
View Full Code Here

        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

     * Tests checking correct handling of parameters and default values
     */
   
    @Test
    public void checkMediaTypeForStreamSource() throws IOException {
        ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
        assertEquals(DEFAULT_MT, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),null);
        assertEquals(DEFAULT_MT, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),null,HEADERS);
        assertEquals(DEFAULT_MT, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),null,FILE_NAME,HEADERS);
        assertEquals(DEFAULT_MT, source.getMediaType());
       
        source = new StreamSource(new ByteArrayInputStream(DATA),MT);
        assertEquals(MT, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),MT,HEADERS);
        assertEquals(MT, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),MT,FILE_NAME,HEADERS);
        assertEquals(MT, source.getMediaType());
        //Parameters MUST BE preserved!
        source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM,HEADERS);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
        source = new StreamSource(new ByteArrayInputStream(DATA),MT_WITH_PARAM,FILE_NAME,HEADERS);
        assertEquals(MT_WITH_PARAM, source.getMediaType());
    }
View Full Code Here

    @POST
    public RdfViewable enhanceFile(MultiPartBody body) throws IOException, EnhancementException {
        final String[] chainValues = body.getTextParameterValues("chain");
        final String chainName = chainValues.length > 0 ? chainValues[0] : null;
        final FormFile file = body.getFormFileParameterValues("file")[0];
        final ContentSource contentSource = new ByteArraySource(
                file.getContent(),
                file.getMediaType().toString(),
                file.getFileName());
        final ContentItem contentItem = contentItemFactory.createContentItem(contentSource);
        if ((chainName == null) || chainName.trim().equals("")) {
View Full Code Here

TOP

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

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.