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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:42:47+00:00 2026-06-08T09:42:47+00:00

I have something akin to the following: public class X extends Thread{ BufferedInputStream in

  • 0

I have something akin to the following:

public class X extends Thread{
    BufferedInputStream in = (BufferedInputStream) System.in;
    public void run() {
        while (true) {
            try {
                while (in.available() > 0) {
                  // interesting stuff here
                }
            } catch (Exception e) {
                e.printStackTrace();
            }                   
        }
    }
}

… which largely works, however sometimes I’ll start seeing the following in stderr (seems to repeat incessantly once it happens – I’m guessing the application eventually crashes once this starts occurring):

java.io.IOException: Illegal seek
    at java.io.FileInputStream.available(Native Method)
    at java.io.BufferedInputStream.available(BufferedInputStream.java:381)
    at compactable.sqlpp.X.run(X.java:40)

… and I have no clue what causes this. Honestly stumped. Any ideas from the masses on how this could happen ?

Any / all useful suggestions gratefully received 🙂

  • 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-08T09:42:50+00:00Added an answer on June 8, 2026 at 9:42 am

    If the stream has been closed you can get an IOException calling available.

    Also, available() does not tell you how much is left to read of the stream or if the stream is empty, it only tells how much you can read without blocking (basically waiting for more to be put into the stream). What you want is to read until your read returns -1.

    int c;
    while ( (c = in.read()) != -1 ) {
      // do stuff
    }
    

    or

    int readLength;
    byte[] buffer = new byte[1024];
    while ( (length = in.read(buffer) != -1) {
      // do stuff with buffer, it now has bytes in buffer[0] to buffer[readLength-1]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Java function: public void foo(Class<? extends Exception> cl, List<? extends Exception>
Does NetBeans have something akin to Set Next Statement/Instruction when debugging in Java?
I have something like the code below: for(int i=0;i<10;i++){ button=new JButton(buttons[i]); button.addActionListener(new ActionListener(){ public
I have something like: Field [] fields = claz.getDeclaredFields(); for(Field f : fields){ f.setAccessible(true);
I have a data.frame that has a number of duplicate rows, akin to something
I have something akin to <Foobar Name='Hello There'/> and need to change the single
Does windows have any decent sampling (eg. non-instrumenting) profilers available? Preferably something akin to
I have something I am trying to achieve. I have a web application running
I have something like this: function showFunction () { // need position and place
I have something of a logical puzzle I can not figure out. I have

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.