Search in sources :

Example 1 with MemoryPayload

use of com.disney.uriparcel.MemoryPayload in project groovity by disney.

the class TestParcels method testString.

@Test
public void testString() throws Exception {
    String val = "TEN FOUR OK \u201c";
    URI uri = new URI("mem:stringTest");
    MemoryContext.put(uri, new MemoryPayload(val.getBytes("UTF-8"), "text/plain;charset=UTF-8"));
    URIParcel<String> parcel = new URIParcel<String>(String.class, uri);
    String rval = parcel.call();
    Assert.assertFalse(rval == val);
    Assert.assertEquals(rval, val);
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) URI(java.net.URI) MemoryPayload(com.disney.uriparcel.MemoryPayload) Test(org.junit.Test)

Example 2 with MemoryPayload

use of com.disney.uriparcel.MemoryPayload in project groovity by disney.

the class TestParcels method testBytes.

@Test
public void testBytes() throws Exception {
    byte[] val = "kirksulu".getBytes();
    URI uri = new URI("mem:bytesTest");
    MemoryContext.put(uri, new MemoryPayload(val, "application/octet-stream"));
    URIParcel<byte[]> parcel = new URIParcel<byte[]>(byte[].class, uri);
    byte[] rval = parcel.call();
    Assert.assertFalse(rval == val);
    Assert.assertArrayEquals(rval, val);
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) URI(java.net.URI) MemoryPayload(com.disney.uriparcel.MemoryPayload) Test(org.junit.Test)

Example 3 with MemoryPayload

use of com.disney.uriparcel.MemoryPayload in project groovity by disney.

the class MemoryStreamStore method getOutputStream.

@Override
public OutputStream getOutputStream(ContentStream uriContent, Map<?, ?> config) throws IOException {
    final URI uri = uriContent.getUri();
    final MemoryPayload payload = new MemoryPayload();
    payload.setContentType(uriContent.getContentType());
    payload.setModified(uriContent.getLastModified());
    return new ByteArrayOutputStream() {

        public void close() throws IOException {
            super.close();
            payload.setPayload(this.toByteArray());
            MemoryContext.put(uri, payload);
        }
    };
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) MemoryPayload(com.disney.uriparcel.MemoryPayload)

Example 4 with MemoryPayload

use of com.disney.uriparcel.MemoryPayload in project groovity by disney.

the class MemoryStreamStore method getInputStream.

@Override
public InputStream getInputStream(ContentStream uriContent, Map<?, ?> config) throws IOException {
    final MemoryPayload payload = MemoryContext.get(uriContent.getUri());
    if (payload == null) {
        throw new FileNotFoundException(uriContent.getUri().toString());
    }
    uriContent.setContentLength(payload.getPayload().length);
    uriContent.setContentType(payload.getContentType());
    uriContent.setLastModified(payload.getModified());
    return new ByteArrayInputStream(payload.getPayload());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) MemoryPayload(com.disney.uriparcel.MemoryPayload)

Aggregations

MemoryPayload (com.disney.uriparcel.MemoryPayload)4 URI (java.net.URI)3 URIParcel (com.disney.uriparcel.URIParcel)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1