Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:45:01+00:00 2026-06-16T19:45:01+00:00

Currently I am trying to read a not so short stream from a response

  • 0

Currently I am trying to read a not so short stream from a response of content length 37743. I am using the read(char[] buffer, int offset, int length), yet not all the stream is being read when comparing it to the original json file I am reading. I’ve tried to check if this is a common issue but I cannot find any reasons why this can be the problem:

  • max length of the String builder?
  • max length of the char[] ?
  • buffer length ? (currently 8192)
  • incorrect while condition ? (following snippet)
while ((reader.read(buffer, 0, buffer.length)) != -1)
     sb.append(String.valueOf(buffer)); //sb is the String builder

Note when the buffer length is changed, the result changes again, e.g. when changed to 1024, the same result obtained with the 8192 buffer was achieved plus another piece of text which is not consistent with the original json string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:45:02+00:00Added an answer on June 16, 2026 at 7:45 pm

    You should never ignore the result of Reader.read(). It returns -1 if the end of the stream is reached. If not, it returns the number of chars that have been read. Assuming that it reads exactly the number of chars you asked it to read is wrong.

    Change it to

    while ((read = reader.read(buffer, 0, buffer.length)) != -1) {
        sb.append(buffer, 0, read);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently am trying to read and write mp3 tags without using any external modules
I'm currently trying to READ XML file from the client machine where the user
So I've read quite about Thread Synchronization in Java. I'm currently trying the Bounded-Buffer
Im currently trying to downlaod a audio track from a WCF, i need some
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I'm currently trying to get the most popular productID from my MSSQL Database. This
I'm currently trying to run MSTest.exe from NCover, but I believe the question could
We're trying to find out some performance fixes reading from a TADOQuery. Currently, we
I was trying to make a simple bubblesort program. Read in numbers from a
I am currently trying to read MSMQ information on a remote machine. The main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.