Results 1 to 4 of 4
  1. #1
    Jeff is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default Trouble with Buffer Sizing

    I'm extremely new to Java. I took the Fundamentals of the Java Programming Language Course a week ago at Sun's training center, and am now trying to apply some of it in preparation for the Cert exam.

    One of the programs I'm trying to write is supposed to read a lot of information over IP, acting as a server. I've managed to create my socket, and create a BufferedReader that can read the data, however, the BufferedReader is filling up at 512 bytes of Data, and I can't figure out how to change it. According to what I've read, when I create the instance, I just need to specify a size, but that doesn't appear to be working. Any ideas?

    This is the code I have. You'll see I tried to create it to be size 1024, but it still stops at 512. It doesn't seem to matter what size I put in. I've tried smaller sizes and bigger sizes, but it always fills up at 512 no matter what.

    Java Code:
    private static Socket s1;
    private BufferedReader input;
    
    public AMXClient()
    {
    	try
    	{
    		s1=new Socket("10.198.9.1",1320);
    		input=new BufferedReader(new InputStreamReader(s1.getInputStream()),1024);
    	}
    	catch(ConnectException connExc)
    	{
    		System.out.println("Could not connect.");
    	}
    }
    I also tried changing the size of the InputStreamReader, thinking that if the inputstreamreader were too small, the bufferedreader's size wouldn't matter, but I get a compile error that says there's no constructor for InputStreamReader that involves an integer.

    Thanks a bunch!
    Last edited by Jeff; 02-04-2008 at 08:40 PM.

  2. #2
    Jeff is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default

    Anybody? I didn't think this was a particularly difficult issue . . . . Is there something more to this than I was aware that makes it more than a quick forum post to solve?

    J

  3. #3
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Source

    Welcome, Jeff, to the forums!

    Your application looks like a client application. So you are reading some data from the server. The buffered reader uses a buffer with size according to your specification. It's basically how big the pages are in a book. If a book contains 512 words and your pages can contain 1024 words then your book will be only one page long. This will affect caching. If a page can only contain 128 words, then the book will have 4 pages, but it will still contain 512 words. So, I think that the source, where you read your data, can only provide 512 bytes of data. It does not depend on the size of your buffer that you use. :D

    I hope this make sense. ;)
    Last edited by tim; 02-07-2008 at 01:38 PM.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  4. #4
    Jeff is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default

    You're correct, I'm acting as the client, not the server. My bad.

    I've written the code for the Server myself, in another language (NetLinx). I'm fairly confident that it is sending significantly more than 512 bytes. This doesn't seem to jive with what you're suggesting . . . .

    I'll play with it a bit more and see if that appears to be the problem.

    J

Similar Threads

  1. Replies: 0
    Last Post: 03-11-2008, 12:25 PM
  2. Help needed with sizing components
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 04:40 AM
  3. Http Buffer issue... chunked?
    By jlew in forum Networking
    Replies: 1
    Last Post: 11-04-2007, 05:45 PM
  4. Help with String Buffer
    By mathias in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM
  5. how to set the value of BUFFER SIZE
    By oregon in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •