Search in sources :

Example 6 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class GeoJsonMetacardTransformer method transform.

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
    JSONObject rootObject = convertToJSON(metacard);
    String jsonText = JSONValue.toJSONString(rootObject);
    return new BinaryContentImpl(new ByteArrayInputStream(jsonText.getBytes(StandardCharsets.UTF_8)), DEFAULT_MIME_TYPE);
}
Also used : JSONObject(org.json.simple.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl)

Example 7 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class BinaryContentImplTest method testBinaryContentImplNullMimeType.

@Test
public void testBinaryContentImplNullMimeType() {
    InputStream is;
    try {
        is = new FileInputStream(content);
        BinaryContentImpl bci = new BinaryContentImpl(is, null);
        assertEquals(null, bci.getMimeType());
    } catch (IOException e) {
        LOGGER.error("IO Failure", e);
        new Failure(null, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 8 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class BinaryContentImplTest method testBinaryContentImpl.

@Test
public void testBinaryContentImpl() {
    InputStream is;
    try {
        is = new FileInputStream(content);
        BinaryContentImpl bci = new BinaryContentImpl(is, mimeType);
        bci.setSize(content.length());
        // assertEquals(is, bci.getInputStream());
        assertEquals(mimeType, bci.getMimeType());
        assertEquals(content.length(), bci.getSize());
        assertNotNull(bci.toString());
    } catch (IOException e) {
        LOGGER.error("IO Failure", e);
        new Failure(null, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 9 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class BinaryContentImplTest method testBinaryContentImplNegativeSize.

@Test
public void testBinaryContentImplNegativeSize() {
    InputStream is;
    try {
        is = new FileInputStream(content);
        BinaryContentImpl bci = new BinaryContentImpl(is, mimeType);
        bci.setSize(-20L);
        assertEquals(-1, bci.getSize());
    } catch (IOException e) {
        LOGGER.error("IO Failure", e);
        new Failure(null, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 10 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class BinaryContentImplTest method testBinaryContentImplByteArrayNotNull.

@Test
public void testBinaryContentImplByteArrayNotNull() {
    InputStream is;
    try {
        is = new FileInputStream(content);
        BinaryContentImpl bci = new BinaryContentImpl(is, mimeType);
        byte[] contents = bci.getByteArray();
        assertNotNull(contents);
    } catch (IOException e) {
        LOGGER.error("IO Failure", e);
        new Failure(null, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Aggregations

BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)33 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)12 Test (org.junit.Test)12 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)11 IOException (java.io.IOException)11 BinaryContent (ddf.catalog.data.BinaryContent)10 HashMap (java.util.HashMap)10 FileInputStream (java.io.FileInputStream)9 Metacard (ddf.catalog.data.Metacard)8 MimeType (javax.activation.MimeType)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)6 Result (ddf.catalog.data.Result)5 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)4 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)4 StringWriter (java.io.StringWriter)4 MimeTypeParseException (javax.activation.MimeTypeParseException)4 Failure (org.junit.runner.notification.Failure)4 CatalogFramework (ddf.catalog.CatalogFramework)3