You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Steve Sun <st...@gmail.com> on 2017/02/06 21:43:42 UTC
Avro throws EOFException when reading bytes
Hi there,
My ``readExternal(input)`` keeps throwing me EOFException.
Here's my Deserializer:
public static SearchMaterializationDto
deserializeToSearchMaterialization(byte[] buffer) {
SearchMaterializationDto searchMaterializationDto = new
SearchMaterializationDto();
try {
ObjectInput input = new ObjectInputStream(new
ByteArrayInputStream(buffer));
searchMaterializationDto.readExternal(input);
} catch (IOException e) {
throw new IOException(e);
}
return searchMaterializationDto;
}
Here's how I'm calling the method:
String endpoint = "http://localhost:8080/api/v1/items?itemIds="
+ URLEncoder.encode(itemIds, "UTF-8");
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(endpoint);
String USER_AGENT = "Mozilla/5.0";
// add request header
request.addHeader("User-Agent", USER_AGENT);
// request.addHeader("Content-Type", "application/json");
request.addHeader("Content-Type", "avro/binary");
HttpResponse response = client.execute(request);
System.out.println("Response Code : "
+ response.getStatusLine().getStatusCode());
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
// for (byte b : bytes){
// System.out.println("b = " + b);
// }
SearchMaterializationDto deserializedReponse =
SearchMaterializationAvroObjectSerializer.deserializeToSearchMaterialization(bytes);
System.out.println(deserializedReponse.toString());
What I'm suspecting is content-type is wrong/unstandard one: "avro/binary",
but it's the one per [Avro spec](
http://avro.apache.org/docs/1.8.1/spec.html#HTTP+as+Transport).
Any help please?
Thanks
Steve