Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending binary data with the Restlet client

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.

like image 829
Yrlec Avatar asked May 24 '09 18:05

Yrlec


People also ask

How do you send binary data?

Sending binary dataThe send method of the XMLHttpRequest has been extended to enable easy transmission of binary data by accepting an ArrayBuffer , Blob , or File object. The following example creates a text file on-the-fly and uses the POST method to send the "file" to the server.

Which method is suitable for passing binary data like images documents?

JSON / XML Probably the easiest and most compatible way to send the data is to serialize it to JSON or XML. Also the binary data, which means getting +33% in message size due to BASE64 compression.

What is this binary data?

Binary data is data whose unit can take on only two possible states. These are often labelled as 0 and 1 in accordance with the binary numeral system and Boolean algebra.


1 Answers

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

Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM);
request.setEntity(representation);
like image 177
Avi Flax Avatar answered Oct 11 '22 13:10

Avi Flax