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);
}
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);
}
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);
}
};
}
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());
}
Aggregations