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 8187427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:33:32+00:00 2026-06-07T02:33:32+00:00

I’m experiencing a strange error with one of our systems that I am at

  • 0

I’m experiencing a strange error with one of our systems that I am at a loss to explain. In our system the backend is generating a large TSV output file which we are then serving across HTTP using the following code:

    BufferedInputStream input = new BufferedInputStream(p.getInputStream(), (int)FileUtils.BYTES_PER_MEGABYTE * 16);
    OutputStream output = resp.getOutputStream();
    byte[] buffer = new byte[(int) (FileUtils.BYTES_PER_KILOBYTE * 8)];
    do
    {
        int read = input.read(buffer);
        if (read <= 0) break;
        output.write(buffer);           
    } while (true);
    input.close();
    output.close();

Then on the client side there is a TSV parser consuming the HTTP response but on very large inputs we start seeing strange artifacts where the parser will report a line as having the wrong number of items and the error message prints the line it will be parsing and that line will be a random chunk of data i.e. not an entire line of the data

My first thought was that the TSV being generated was malformed but I’ve pretty much ruled this out by copying the file directly from the backend system and then running it through three independently written open source TSV parsers (including the one the client code is using) and all of them are capable of parsing the file fine when running on the local file.

For reference the code for the TSV parser we’re using is here

This leads me to two possibilities:

  1. The code I’ve shown for copying the file across HTTP is flawed in some way – in which case I’d love for someone to point out what dumb but non-obvious mistake I’ve made!
  2. BufferedReader.readLine() which is being used by the consuming parser is not guaranteed to read whole lines? I’d wouldn’t be entirely surprised if this is the case as I’ve been bitten by strange read behavior over slow network streams in .Net so wonder if a similar problem can apply in Java?

Or is there some other explanation I’ve overlooked?

  • 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-07T02:33:33+00:00Added an answer on June 7, 2026 at 2:33 am

    In posting this question I suddenly spotted what the error was (typically!)

    The following portion of the code I posted for copying the file is incorrect:

    int read = input.read(buffer);
    if (read <= 0) break;
    output.write(buffer);
    

    It should instead be as follows:

    int read = input.read(buffer);
    if (read <= 0) break;
    output.write(buffer, 0, read);
    

    The problem being that I was always writing the whole buffer to the output stream even when we’d read less from the input than the size of the buffer. This meant that at the end of the file we’d print the last chunk of the data and whatever was left in the rest of the buffer hence the random chunk of data left over!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.