[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: InputStream



  public void run() {
    int i;
    try {
      while(true) {
        in.mark(1);
        i = in.read();
        System.out.print("[" + (char)i + "]");
        if(Main.sock.isConnected() == false) {
          System.err.println("Remote host closed connection");
          System.exit(0);
        }
        out.write((byte)i);
        out.flush();
      }
    } catch (Exception e) {


If I type Hello, I does not display [H] after the first H, it waits till
I press return to.  The tty is passed to Java in cooked mode and must be
converted by java in raw mode.  This is the key.  Otherwise, I'l write
this in C :(



On Tue, 2003-01-28 at 13:45, John Wells wrote:
> Chris,
> 
> Hmm...afaik System.in.read() should only read the next byte from the
> stream.
> 
> Have you attempted to print the char/byte out to see exactly what you're
> getting?
> 
> When you say it's behaving in line mode, what is leading you to believe
> this?  Can you provide a sample of what you're trying to read in, and
> what you're actually getting?
> 
> If you're inputing from the command line, it's buffered input using
> readline(), I believe, so System.in.read() in your Java program won't get
> any characters until your shell sees a newline and submits.
> 
> John
> 
> cfowler said:
> > Is there a way to convert an InputStream like System.in. from what
> > appears to be line-mode to char mode?
> >
> > I'm doing this:
> >
> > int i = System.in.read();
> > sockOutStream.write(i);
> >
> > It behaves as if I'm in line mode.
> 
> 
>