I posted questions about this topic twice (here and herehere but never got a satisfying answer, it felt like I could not articulate the question well enough. I have since figured it out but my understanding of it is weak. It was chance that led me to this solution. What I am doing it is generating results on a seperate process spawned by my webserver. As those results are generated I want to use Jersey to stream the bytes to the webserver and eventually that will get passed back to my client (at a later time). I had the hardest time figuring out how to make my data stream from my process back to my webserver. I guessed that using a StreamingOuput type for my Entity would work. There are not examples on the web of this, can anyone explain what is going on in Jersey land. I was stunned that I was able to read the data out on the webserver as an InputStream.
Running in my servlet container on the server
@PUT
@Path("groups/{myUuid:" + Regex.UUID + "}")
public void updateSpectraData(@PathParam("myUuid") UUID myUuid, InputStream inputStream)
{
float[] floatHolder = new float[512];
byte[] bytes = ByteStreams.toByteArray(inputStream);
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.asFloatBuffer().get(floatHolder);
System.out.println(Arrays.toString(floatHolder));
}
The code below is running in a separate process spawned by the server.
private void doPut(byte[] data, Object ctx)
{
final Client client = ClientBuilder.newClient();
ObjectMapper objectMapper = new ObjectMapper();
MyTask myTask = objectMapper.readValue(data, MyTask.class);
MyConifguration config = getConfig();
WebTarget createTaskTarget = client.target(myTask.getURI());
Builder request = createTaskTarget.request(MediaType.APPLICATION_OCTET_STREAM);
request.put(Entity.entity(createData(config), MediaType.APPLICATION_OCTET_STREAM), InputStream.class);
}
Here is the function which creates the data, the return type is what is important:
private StreamingOutput createData(MyConfiguration config)
{
return new StreamingOutput()
{
...code...
}
}