In short, look at the "str" variable below. The output of it, is the entire result of the PING operation.
reader = new BufferedReader(new InputStreamReader (process.getInputStream()));
int j;
char[] buffer = new char[240];
StringBuffer output = new StringBuffer();
while ((j = reader.read(buffer)) > 0){
output.append(buffer, 0, j);}
str = output.toString();
Log.d("1:STR VALUE", str);
publishProgress(" "+str+" ");
The "str" variable contains the entire result of the operation, i.e. 3 pings to an IP address. However, I want to display pings line by line, one by one on to the Android activity, from this Async task.
In addition, if someone could explain the performance constraints of the length of the buffer array I am using (i.e. 240 vs say 120), that would be great.
EDIT-1 (response to comment):
11-28 18:11:17.404 10769-10815/com.example1 D/1:STR VALUE: PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=8.83 ms
11-28 18:11:17.600 10769-10815/com.example1 D/1:STR VALUE: PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=8.83 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=2.05 ms
11-28 18:11:17.801 10769-10815/com.example1 D/1:STR VALUE: PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=8.83 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=2.05 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=3.38 ms
--- 192.168.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 403ms
rtt min/avg/max/mdev = 2.059/4.758/8.835/2.933 ms
Please note that when the STR value is published inside the while loop, repetition of output occurs.