when i tryin to make thme method .toByteArray(); always fall in a exception, but the log doesn´t show, what can be the problem:
protected byte[] GetResponseBytes(HttpURLConnection conn)
{
byte[] data2 = null;
try
{
int nRead;
byte[] data = new byte[16384];
InputStream is = conn.getInputStream();
ByteArrayOutputStream buff = new ByteArrayOutputStream();
while ((nRead = is.read(data, 0, data.length)) != -1)
buff.write(data, 0, nRead);
buff.flush();
buff.close();
is.close();
data2 = buff.toByteArray();
return data2;
}
catch (Exception ex)
{
Log.d(" ERROR ", "[ data loader - post response bytes ] "+ex.getMessage());
return data2;
}
}
and i call the method like this:
byte[] data = GetResponseBytes(conn);
element = parser.parseFrom(data);
the parser is a protocolBuffer and make an excepcion