ix.util
Class Util

java.lang.Object
  |
  +--ix.util.Util

public class Util
extends java.lang.Object

Class for useful static methods.


Constructor Summary
Util()
           
 
Method Summary
static java.lang.String askLine(java.lang.String prompt)
          Simple, text-based user interaction.
static java.lang.String[] breakStringAtFirst(java.lang.String s, java.lang.String separator)
          breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after.
static void printLines(java.lang.String[] lines)
          Print the elements of a String[] array to System.out as lines.
static java.lang.String readLine(java.io.InputStream is)
          Reads a line from an InputStream and returns it as a String.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

breakStringAtFirst

public static java.lang.String[] breakStringAtFirst(java.lang.String s,
                                                    java.lang.String separator)
breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after. Neither substring contains the delimiter. If the delimiter does not appear in the string at all, the values are the string and "".

printLines

public static void printLines(java.lang.String[] lines)
Print the elements of a String[] array to System.out as lines.

askLine

public static java.lang.String askLine(java.lang.String prompt)
Simple, text-based user interaction. askLine pronts a prompt to System.out and returns a String containing the next line from System.in.

If askLine blocks when reading, we'd like other threads to be able to run; but that doesn't seem to happen reliably. Presumably, this is a bug. In any case, askLine works around the problem by having a loop that checks whether input is available and sleeps for a second if it isn't.


readLine

public static java.lang.String readLine(java.io.InputStream is)
Reads a line from an InputStream and returns it as a String. In Java, we seem to have to write this ourself unless we wrap a special stream (or Reader) around whatever we want to read. Here we provide a static method, because that's easier to mix with other operations. The only InputStream method called is read().