Default Buffer size in BufferedReader

Put your problem here if it does not fit any of the other categories.

Default Buffer size in BufferedReader

Postby achie1266 » Tue Dec 29, 2009 8:38 pm

I am using BufferedReader in my application and if I do not set a default Buffer size it gives me this message in logcat
Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
It works fine when I set a default buffersize.

My doubt is what is the default buffer size used for. It may be more of a java doubt than an android doubt.

any info is appreciated.

Thank you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby hardcoras » Thu Dec 31, 2009 12:49 am

Below is a code fragment from Android source. The log message isn't lying :D Buffer's size is 8k-chars wide.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. /**
  3.  
  4.      * Constructs a new BufferedReader on the Reader {@code in}. The
  5.  
  6.      * buffer gets the default size (8 KB).
  7.  
  8.      *
  9.  
  10.      * @param in
  11.  
  12.      *            the Reader that is buffered.
  13.  
  14.      */
  15.  
  16.     public BufferedReader(Reader in) {
  17.  
  18.         super(in);
  19.  
  20.         this.in = in;
  21.  
  22.         buf = new char[8192];
  23.  
  24.  
  25.  
  26.         // BEGIN android-added
  27.  
  28.         /*
  29.  
  30.          * For Android, we want to discourage the use of this
  31.  
  32.          * constructor (with its arguably too-large default), so we
  33.  
  34.          * note its use in the log. We don't disable it, nor do we
  35.  
  36.          * alter the default, however, because we still aim to behave
  37.  
  38.          * compatibly, and the default value, though not documented,
  39.  
  40.          * is established by convention.
  41.  
  42.          */
  43.  
  44.         Logger.global.info(
  45.  
  46.                 "Default buffer size used in BufferedReader " +
  47.  
  48.                 "constructor. It would be " +
  49.  
  50.                 "better to be explicit if an 8k-char buffer is required.");
  51.  
  52.         // END android-added
  53.  
  54.     }
  55.  
  56.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby achie1266 » Thu Dec 31, 2009 1:23 am

lol I know that the log is not lying that the buffersize is ~8192. In fact the docs clearly explain that.

My doubt is what is the buffer size being used for. It may be helpful if you post the whole BufferedReader class.

Thank you,
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby hardcoras » Thu Dec 31, 2009 1:35 am

You can get full class source from Android source tree.

I misunderstood your question. Pardon me.

Quick answer: Buffer size shows the amount of data to read at one loop cycle.

The BufferedReader class provides buffering to your Reader's. Buffering can speed up IO quite a bit. Rather than read one character at a time from the network or disk, you read a larger block at a time. This is typically much faster, especially for disk access and larger data amounts.

Source: http://tutorials.jenkov.com/java-io/bufferedreader.html

P.S. Happy New Year :)
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby achie1266 » Thu Dec 31, 2009 1:39 am

Thank you for the link.

Happy new year 2 u 2..
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests