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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:35:35+00:00 2026-06-15T09:35:35+00:00

I have an IInputStream that I want to read data from until I encounter

  • 0

I have an IInputStream that I want to read data from until I encounter a certain byte, at which point I will pass the IInputStream to some other object to consume the rest of the stream.

This is what I’ve come up with:

public async Task HandleInputStream(IInputStream instream)
{
    using (var dataReader = new DataReader(instream))
    {
        byte b;
        do
        {
            await dataReader.LoadAsync(1);
            b = dataReader.ReadByte();

            // Do something with the byte
        } while (b != <some condition>);

        dataReader.DetachStream();
    }
}

It seems like running LoadData for one byte at a time will be horribly slow. My dilemma is that if I pick a buffer size (like 1024) and load that, and my value shows up 10 bytes in, then this method will have the next 1014 bytes of data and will have to pass it to the next method for processing.

Is there a better way to approach this, or is this an acceptable solution?

  • 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-15T09:35:36+00:00Added an answer on June 15, 2026 at 9:35 am

    If the value you’re looking for is not too far from the beginning of the stream, this kind of reading shouldn’t be that slow. How far into the stream are you expecting it? Have you tested the performance?

    Depending on the type of stream you are using, you might be able to use other approaches:

    • If it supports seeking backwards (e.g. you’re reading from a file), you could read larger chuncks at once as long as you know at what offset you have found your value. You can then seek into the stream to that position before you hand it off.
    • If that’s not possible you could create another intermediate memory stream into which you would copy the remaining part of the buffer you have already read, followed by the rest of the stream. This works even if you can’t seek backwards. The only problem might be memory consumption if the stream is too large.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed J2ME application that read data from product.txt file located in binary
I have 52 images that is coming from web URL.I want to display this
I have a program that needs to process data from Standard-In. I can call
I have an application that communicates to server. I want my application to READ
I want to read multiple objects (my own class Term) that I have output
I have a service that reads real-time sensor data. The data is read in
I am passing data from swing to servlet using http url connection.I have passed
I have an app that backs up data to the sd card. When the
I'm looking to read from a XML file which is stored within a zip
What I want to do is log the output from an inputstream that I

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.