@ApiOperation(value = "Get a datastream from a ReDBox object", tags = "datastream")
@ApiImplicitParams({
@ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") })
@ApiResponses({ @ApiResponse(code = 200, message = "The datastream is retrieved"),
@ApiResponse(code = 500, message = "General Error", response = Exception.class) })
@Get("application/octet-stream")
public Representation getDatastream() throws IOException {
try {
Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage");
String oid = getAttribute("oid");
String payloadId = getQueryValue("datastreamId");
if (payloadId != null) {
DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid);
Payload payload = digitalObject.getPayload(payloadId);
return new ByteArrayRepresentation(IOUtils.toByteArray(payload.open()));
} else {
throw new ResourceException(400, "Call requires a datastreamId value");
}
} catch (StorageException e) {
throw new ResourceException(500, e, e.getMessage());
}
}