Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wrong usage of BufferedReader

s=new Scanner(new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream())));

        while(s.hasNext()){
             System.out.println("Am intrat in bucla s:");
             longitude=Integer.parseInt(s.next());
             System.out.println("Valoare longitudine:"+longitude);
             latitude=Integer.parseInt(s.next());
             System.out.println(latitude);

I'm using the lines above to read some data from a client-server connection;this is the server side.The data are read in scanner s and after that I try to display it,but when I look in logcat I have nothing display but this exception:

04-18 00:07:56.138: INFO/global(295): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.

Both my client and server are on android!Does anyone have any idea what I'm doing wrong?

This is how I read the data,I send latitude and longitude,I assume that is blank spaces delimited,the strange thing is that sometimes is working:

        Cursor c=db.getAllData();

           if(c.moveToFirst()) 
             {
              do{

                  longitude=Integer.parseInt(c.getString(1));
                  out.println(longitude);
                  latitude=Integer.parseInt(c.getString(2));
                  out.println(latitude);

              }while(c.moveToNext());

             }
like image 339
adrian Avatar asked Apr 18 '11 12:04

adrian


1 Answers

The message seems to be for the BufferedReader construct.

First, I do not think you are doing anything "wrong", since you are saying that the code works as expected and the message is "INFO", not "ERROR" or even "WARNING".

Second, if you look at the BufferedReader constructor, you will see:

BufferedReader(Reader in, int size) Constructs a new BufferedReader, providing in with size characters of buffer.

http://developer.android.com/reference/java/io/BufferedReader.html

Use that constructor instead and you should not see that message.

BTW, the logcat is full of output, some lines are more relevant than others.


Use Log.d instead of System.out.println(). Regarding System.out: http://developer.android.com/guide/developing/tools/adb.html

Viewing stdout and stderr

By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null. In processes that run the Dalvik VM, you can have the system write a copy of the output to the log file. In this case, the system writes the messages to the log using the log tags stdout and stderr, both with priority I.

To route the output in this way, you stop a running emulator/device instance and then use the shell command setprop to enable the redirection of output. Here's how you do it:

$ adb shell stop $ adb shell setprop log.redirect-stdio true $ adb shell start

The system retains this setting until you terminate the emulator/device instance. To use the setting as a default on the emulator/device instance, you can add an entry to /data/local.prop on the device.

like image 76
Aleadam Avatar answered Oct 28 '22 00:10

Aleadam