1 34 package org.codehaus.groovy.runtime; 35 36 import java.io.IOException ; 37 import java.io.Writer ; 38 39 47 public class StringBufferWriter extends Writer { 48 49 private StringBuffer buffer; 50 51 54 public StringBufferWriter(StringBuffer buffer) { 55 this.buffer = buffer; 56 } 57 58 61 public void write(int c) { 62 buffer.append((char) c); 63 } 64 65 72 public void write(char text[], int offset, int length) { 73 if ((offset < 0) || (offset > text.length) || (length < 0) || ((offset + length) > text.length) || ((offset + length) < 0)) { 74 throw new IndexOutOfBoundsException (); 75 } 76 else if (length == 0) { 77 return; 78 } 79 buffer.append(text, offset, length); 80 } 81 82 85 public void write(String text) { 86 buffer.append(text); 87 } 88 89 96 public void write(String text, int offset, int length) { 97 buffer.append(text.substring(offset, offset + length)); 98 } 99 100 103 public String toString() { 104 return buffer.toString(); 105 } 106 107 110 public void flush() { 111 } 112 113 118 public void close() throws IOException { 119 } 120 } 121 | Popular Tags |