001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.util.io;
018:
019: import java.io.Writer;
020:
021: import org.apache.wicket.util.string.AppendingStringBuffer;
022:
023: /**
024: * @author jcompagner
025: */
026: public class StringBufferWriter extends Writer {
027: /** The buffer which holds the chars */
028: private AppendingStringBuffer buffer;
029:
030: /**
031: * Constructor
032: */
033: public StringBufferWriter() {
034: buffer = new AppendingStringBuffer(4096);
035: }
036:
037: /**
038: * @return The AppendingStringBuffer with the written data
039: */
040: public AppendingStringBuffer getStringBuffer() {
041: return buffer;
042: }
043:
044: /**
045: * @param buffer
046: */
047: public void setStringBuffer(AppendingStringBuffer buffer) {
048: this .buffer = buffer;
049: }
050:
051: /**
052: * Writers the char to the buffer
053: *
054: * @param ch
055: */
056: public void write(char ch) {
057: buffer.append(ch);
058: }
059:
060: /**
061: * @see java.io.Writer#write(char[])
062: */
063: public void write(char charArray[]) {
064: buffer.append(charArray);
065: }
066:
067: /**
068: * @see java.io.Writer#write(char[], int, int)
069: */
070: public void write(char charArray[], int offset, int length) {
071: buffer.append(charArray, offset, length);
072: }
073:
074: /**
075: * @see java.io.Writer#write(java.lang.String)
076: */
077: public void write(String string) {
078: buffer.append(string);
079: }
080:
081: /**
082: * @see java.io.Writer#write(java.lang.String, int, int)
083: */
084: public void write(String string, int offset, int length) {
085: buffer.append(string.substring(offset, offset + length));
086: }
087:
088: /**
089: * @see java.io.Writer#flush()
090: */
091: public void flush() {
092: }
093:
094: /**
095: * resets the buffer.
096: */
097: public void reset() {
098: buffer.setLength(0);
099: }
100:
101: /**
102: * @see java.io.Writer#close()
103: */
104: public void close() {
105: }
106:
107: }
|