• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting garbage characters when reading the java.io.inputstream

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to read the data using inputstream, that has been written out by a product (solaris machine) onto its output stream.

I am getting all the data, however I get a whole bunch of garbage characters in between the data.

I am collecting the data in a byte array directly from the inputstream.

Can anyone tell me why I might be facing this problem ?

I have tried using Reader and providing different charset values, but it is not working.

Here's the output with garbage (unhighlighted part)

Last login: Wed Dec 23 22:16:34 2009 from 148.147.152.191

Sun Microsystems Inc. SunOS 5.9 Generic May 2002
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
TERM is: vt100


 H H H H H H H H H
7tsdexpert:/export/home/pshindikar $

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which server are you connecting to? Your own Java server, telnet, SSH, ...? Can you figure out which charset is used on that server? Because if you just try some randomly and you don't find the right one then you won't convert the bytes to chars properly.
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks like escape sequences for a VT100 terminal emulator. \x1b[3g then all the \x1bH sequences reset the tab stops, \x1b7 saves the cursor position,x1b[r resets scrolling, \x1b999;999H scrolls to the bottom of the screen, then \x1b6 restores the cursor position.

Is there any other way to get to the server that doesn't expect a terminal emulator to be connected?
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob Prime,

Yes, I am connecting to a SSH server on the remote machine.

If I try to connect to the same machine manually using PUTTY, I do not see these sequences. But if I try to read them on the stream, I see these sequences ?

I have also tried to create a reader using charset - ISO-8859-1 (as is used by PUTTY) but was not able to accomplish the same result.

Carey Evans,

That is a very good observation. Thanks! Are you aware if there is some way in which i can ignore these sequences while reading ? I am also looking at connecting to the same server, bypassing the VT100 terminal emulator. Do you think there can be a charset mismatch issue ??
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also figured out that PUTTY uses XTERM as its default Terminal.

Can we set the TERM environ variable to point to say "xterm". If yes, can you tell me how to do it ?

I am taking PUTTY as example, simply because manually I connect using PUTTY and it does not show any escape sequences!
 
Carey Evans
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PuTTY reads the escape sequences, and uses them to position the cursor, clear the screen, etc. You could try passing the TERM environment variable as xterm, but that would just give you slightly different escape sequences.

You should be able to configure your SSH connection not to allocate a pseudo-terminal, or to run your remote program directly instead of the shell, or both, and not get any escape sequences. It's hard to say more without knowing which SSH library you're using, or what program you're running on Solaris.
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the JSCH SSH library for connections.

What is bugging me is the fact that I connected to at least 10 different machines (Linux / Solaris) where the terminal is set to VT100 by default and the code worked fine (ie, i have not received any escape sequences).

So I doubt if I should really get into the configuration of a SSH connection through JSch.
 
Carey Evans
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be that there is something in /etc/profile or $HOME/.profile on that machine that is sending the escape sequences, like reset or tput, a different PS1 setting, or a different shell like bash or ksh instead of sh.

The rsync program has similar problems running over SSH, and they have some more about it in their FAQ: http://www.samba.org/rsync/FAQ.html#3.
 
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic