7

I'm trying to send a byte[] (using PUT) with Restlet but I can't find any info on how to do it. My code looks like this:

Request request = new Request(Method.PUT, url);
request.setEntity( WHAT DO I PUT HERE?, MediaType.APPLICATION_OCTET_STREAM);

I had expected to find something along the lines of ByteArrayRepresentation, just like there's a JsonRepresentation and a a StringRepresentation but I couldn't find anything.

Yrlec
  • 3,401
  • 6
  • 39
  • 75

3 Answers3

7

I believe you want to use an InputRepresentation, like so:

Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM);
request.setEntity(representation);
Avi Flax
  • 50,872
  • 9
  • 47
  • 64
1

I'm not familiar with restlet, but one way to do it would be to base64 encode the data. Then you could handle it like a regular string.

Emil H
  • 39,840
  • 10
  • 78
  • 97
  • Thanks Emil but that is not efficient enough in this case. This code will be sending large amounts of data so having to send 33% more data is not an option. – Yrlec May 24 '09 at 18:26
  • Yeah, kinda figured. Thought I'd mention it anyway, though. :) – Emil H May 24 '09 at 19:24
1

you can try subclassing WritableRepresentation that is especially designed for large representations

dfa
  • 114,442
  • 31
  • 189
  • 228