ported from applet to CLI (read from InputStream instead of String)