1 28 29 package com.caucho.vfs; 30 31 import java.io.IOException ; 32 import java.io.UnsupportedEncodingException ; 33 import java.io.Writer ; 34 import java.util.logging.Level ; 35 import java.util.logging.Logger ; 36 37 40 public class WriterStreamImpl extends StreamImpl { 41 private static Logger log 42 = Logger.getLogger(WriterStreamImpl.class.getName()); 43 44 private Writer _writer; 45 private ByteToCharWriter _byteToChar = new ByteToCharWriter(); 46 private boolean _isClosed; 47 48 51 public void setWriter(Writer writer) 52 { 53 _writer = writer; 54 _byteToChar.setWriter(writer); 55 _isClosed = false; 56 57 try { 58 _byteToChar.setEncoding(null); 59 } catch (UnsupportedEncodingException e) { 60 log.log(Level.WARNING, e.toString(), e); 61 } 62 } 63 64 67 public boolean canWrite() 68 { 69 return true; 70 } 71 72 75 public void setWriteEncoding(String encoding) 76 { 77 try { 78 _byteToChar.setEncoding(encoding); 79 } catch (UnsupportedEncodingException e) { 80 log.log(Level.WARNING, e.toString(), e); 81 } 82 } 83 84 92 public void write(byte []buffer, int offset, int length, boolean isEnd) 93 throws IOException 94 { 95 if (_isClosed) 96 return; 97 98 for (int i = 0; i < length; i++) 99 _byteToChar.addByte(buffer[offset + i]); 100 101 _byteToChar.flush(); 102 } 103 104 107 public void flush() throws IOException 108 { 109 } 110 111 114 public void close() 115 { 116 _isClosed = true; 117 } 118 } 119 | Popular Tags |