Example #1
0
    public void write(int c) throws IOException {
      // TODO: We should actually count the Utf-8 bytes, not the characters.
      if (c == '\n') {
        // Reset the character count.
        counter = 0;
      } else if (counter == 70) {
        // Insert a newline and a space.
        super.write('\n');
        super.write(' ');

        counter = 2;
      } else {
        counter++;
      }

      super.write(c);
    }
 public void write(int c) throws IOException {
   if ((c >= ' ' && c <= '\u007e') || c == '\r' || c == '\n') super.write(c);
   else {
     super.write('\\');
     super.write('u');
     String number = Integer.toHexString(c);
     if (number.length() < 4) number = zeros.substring(0, 4 - number.length()) + number;
     super.write(number.charAt(0));
     super.write(number.charAt(1));
     super.write(number.charAt(2));
     super.write(number.charAt(3));
   }
 }