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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:46:58+00:00 2026-05-16T22:46:58+00:00

public static void ReadWholeArray (Stream stream, byte[] data) { int offset=0; int remaining =

  • 0
public static void ReadWholeArray (Stream stream, byte[] data)
{
    int offset=0;
    int remaining = data.Length;
    while (remaining > 0)
    {
        int read = stream.Read(data, offset, remaining);
        if (read <= 0)
            throw new EndOfStreamException(String.Format("End of stream reached with {0} bytes left to read", remaining));
        remaining -= read;
        offset += read;
     }
}

size of byte array data is 2682
on the first iteration of while loop
the value of read is 1658
on the next iteration
after executing the line

int read = stream.Read(data, offset, remaining);

the program is not responding

what is the problem?

  • 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-05-16T22:46:58+00:00Added an answer on May 16, 2026 at 10:46 pm

    Whatever is providing your stream is blocking until data is available. From MSDN’s docs on Stream.Read:

    The implementation will block until at
    least one byte of data can be read, in
    the event that no data is available.
    Read returns 0 only when there is no
    more data in the stream and no more is
    expected (such as a closed socket or
    end of file)

    You can set a read timeout on the stream to prevent blocking forever.

    As an aside, note that reading from the stream will move the current position, so with your offset logic you may be skipping large chunks of the input stream.

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

Sidebar

Related Questions

public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);
public class MultiplicationTable { public static void main (String[]a){ int[] x; x = new
public static void main(String[] args) { staples[] stemp = new staples[8]; int j; try
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat =
public static void DeleteThreads(int threadID) { StringBuilder sb = new StringBuilder(); sb.Append(DELETE FROM dbo.Threads);
public static void main (String args[]) { Scanner myinput=new Scanner(System.in) ; //Arrary length comes
public static void glDrawElements(int mode, int count, int type, int offset) public static void
public static void fillCheckList(string ListType,int RecordNum,CheckBox chkRequired,TextBox txtComplete,TextBox txtMemo) { string sql_Check = String.Format(@SELECT
public static void Main() { Dictionary<string, double> values = new Dictionary<string, double>(); values.Add(a, 0.002);

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.