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

  • Home
  • SEARCH
  • 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 8766359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:31:58+00:00 2026-06-13T16:31:58+00:00

I am getting a input stream from apache’s telnet client.Every time I send a

  • 0

I am getting a input stream from apache’s telnet client.Every time I send a command to telnet client it writes the terminal output back to InputStream,but this stream remains open until the telnet session.

Now I want a way to read the data on this stream till the end.Problem is end can’t be determined as the stream is always open.One workaround I found was to read data till a specific character is encountered(which is prompt in most of the cases).but the prompt keeps on changing based on command and I have no way to know what it ll be after command execution.

there is a similar question on SO which explains it better but there is no answer :

Problems with InputStream

Please help…

  • 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-13T16:31:59+00:00Added an answer on June 13, 2026 at 4:31 pm

    finally I did using timeout.So basically,I did that ,if character is not available for 1 sec then give up.Instead of inputStream.read() I used this :

    private char readChar(final InputStream in){
            ExecutorService executor = Executors.newFixedThreadPool(1);
            //set the executor thread working
            Callable<Integer> task = new Callable<Integer>() {
                public Integer call() {
                   try {
                       return in.read();
                   } catch (Exception e) {
                      //do nothing
                   }
                   return null;
                }
             };
    
             Future<Integer> future = executor.submit(task);
             Integer result =null;
             try {
                  result= future.get(1, TimeUnit.SECONDS); //timeout of 1 sec
              } catch (TimeoutException ex) {
                  //do nothing
              } catch (InterruptedException e) {
                 // handle the interrupts
              } catch (ExecutionException e) {
                 // handle other exceptions
              } finally {
                  future.cancel(false);
                  executor.shutdownNow();
               }
    
             if(result==null)
                 return (char) -1;
            return  (char) result.intValue();
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with getting input from the command line before opening a
I am designed a dynamic table for getting input from user. Each column of
I'm using ncurses for simple UI that involves getting input from the user. The
The above emulator image is just getting the input from the user and showing
When I input locations from a txt file I am getting a peculiar error
// Create a scanner that reads from the input stream passed to us CSLexer
I'm getting console input from the user and want to encode it to UTF-8.
I am getting this error from the logcat org.apache.http.NoHttpResponseException: The target server failed to
I am having tough time getting to read data from excel 2007. I am
The strings I'm (programmatically) getting from MS Word files when using Apache POI are

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.