1 52 53 package com.go.trove.io; 54 55 import java.io.Writer ; 56 import java.io.IOException ; 57 58 65 public class CharToByteBufferWriter extends Writer { 66 private CharToByteBuffer mBuffer; 67 private boolean mClosed; 68 69 public CharToByteBufferWriter(CharToByteBuffer buffer) { 70 mBuffer = buffer; 71 } 72 73 public void write(int c) throws IOException { 74 checkIfClosed(); 75 mBuffer.append((char)c); 76 } 77 78 public void write(char[] chars) throws IOException { 79 checkIfClosed(); 80 mBuffer.append(chars); 81 } 82 83 public void write(char[] chars, int offset, int length) 84 throws IOException { 85 checkIfClosed(); 86 mBuffer.append(chars, offset, length); 87 } 88 89 public void write(String str) throws IOException { 90 checkIfClosed(); 91 mBuffer.append(str); 92 } 93 94 public void write(String str, int offset, int length) throws IOException { 95 checkIfClosed(); 96 mBuffer.append(str, offset, length); 97 } 98 99 public void flush() throws IOException { 100 checkIfClosed(); 101 } 102 103 public void close() { 104 mClosed = true; 105 } 106 107 private void checkIfClosed() throws IOException { 108 if (mClosed) { 109 throw new IOException ("Writer closed"); 110 } 111 } 112 } 113 | Popular Tags |