public class OBrailler {    char dotChar = 'o';  int indent = 3;    public OBrailler() { }  public OBrailler(char dot) { dotChar = dot; }  public String getBraille(String s, int lineLength) { // better implemented as a stream?    StringBuffer line1=new StringBuffer(),                 line2=new StringBuffer(),                 line3=new StringBuffer(),                 theBraille = new StringBuffer();    if (s==null) return null;    StringBuffer curWord;    for(int i=0; i<s.length(); ) {      curWord = new StringBuffer();      while(i<s.length() && !Character.isWhitespace(s.charAt(i))) {        curWord.append(s.charAt(i));        i++;      }      while(i<s.length() && Character.isWhitespace(s.charAt(i))) {        curWord.append(s.charAt(i));        i++;      }      if (line1.length() != 0 && line1.length()+5*curWord.length() > lineLength) {        theBraille.append(line1);        theBraille.append('\n');        theBraille.append(line2);        theBraille.append('\n');        theBraille.append(line3);        theBraille.append("\n\n");        line1=new StringBuffer();        line2=new StringBuffer();        line3=new StringBuffer();      }      //System.out.println("drawing "+curWord);      for(int j=0; j<curWord.length(); j++) {        if (line1.length()+5 > lineLength) {          theBraille.append(line1);          theBraille.append('\n');          theBraille.append(line2);          theBraille.append('\n');          theBraille.append(line3);          theBraille.append("\n\n");          line1=new StringBuffer();          line2=new StringBuffer();          line3=new StringBuffer();        }        boolean[] theDots = Brailler.getDots(curWord.charAt(j));        if (theDots == null) {          String cs = ""+curWord.charAt(j)+curWord.charAt(j)+curWord.charAt(j);          line1.append(cs+"  ");          line2.append(cs+"  ");          line3.append(cs+"  ");        }        else {          if (theDots[0]) line1.append(dotChar+" ");          else            line1.append(       "  ");          if (theDots[1]) line2.append(dotChar+" ");          else            line2.append(       "  ");          if (theDots[2]) line3.append(dotChar+" ");          else            line3.append(       "  ");          if (theDots[3]) line1.append(dotChar+"  ");          else            line1.append(       "   ");          if (theDots[4]) line2.append(dotChar+"  ");          else            line2.append(       "   ");          if (theDots[5]) line3.append(dotChar+"  ");          else            line3.append(       "   ");        }        if (curWord.charAt(j)=='\r' || curWord.charAt(j)=='\n') {          theBraille.append(line1);          theBraille.append('\n');          theBraille.append(line2);          theBraille.append('\n');          theBraille.append(line3);          theBraille.append("\n\n");          line1=new StringBuffer("               "); // 15 spaces          line2=new StringBuffer("               ");          line3=new StringBuffer("               ");        }      }    }    theBraille.append(line1);    theBraille.append('\n');    theBraille.append(line2);    theBraille.append('\n');    theBraille.append(line3);    return theBraille.toString();  }    public static void main(String[] args) throws Exception {    if (args.length==0) {      System.out.println("Use: java OBrailer [-raw] [-l lineLength] [-c dotChar] text");      System.exit(0);    }    boolean raw=false;    char dotChar='o';    int lineLength = 80;    int curArg = 0;    while(args[curArg].charAt(0)=='-') {      if (args[curArg].charAt(1)=='r') raw=true;      if (args[curArg].charAt(1)=='l') lineLength = Integer.parseInt(args[++curArg]);      if (args[curArg].charAt(1)=='c') dotChar    = args[++curArg].charAt(0);      curArg++;    }    String s=args[curArg];    for(int i=curArg+1; i<args.length; i++) s = s + " " + args[i];    if (!raw) {      try {        java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(s.length()*2);        BrailleOutputStream bOut = new BrailleOutputStream(out);        bOut.write(s.getBytes());        bOut.flush();        s = out.toString();      }      catch (java.io.IOException e) { System.out.println(e); } // should never get this    }    OBrailler theBrailler = new OBrailler(dotChar);    String br = theBrailler.getBraille(s, lineLength);    System.out.println(br);  }  }