Wondering regarding code below that reads data from TCP Socket BufferedInputStream
. Is there any reason read first byte with int s = _in.read()
and later rest ones _in.read(byteData);
. Can I read just byte[] without using first read line?
private static String readInputStream(BufferedInputStream _in) throws IOException
{
String data = "";
int s = _in.read();
if(s==-1)
return null;
data += ""+(char)s;
int len = _in.available();
System.out.println("Len got : "+len);
if(len > 0) {
byte[] byteData = new byte[len];
_in.read(byteData);
data += new String(byteData);
}
return data;
}