1 30 31 package com.nightlabs.io; 32 33 import java.io.*; 34 import java.io.IOException ; 35 36 40 public class DataBufferOutputStream extends OutputStream 41 { 42 DataBuffer dataBuffer; 43 44 protected DataBufferOutputStream(DataBuffer _dataBuffer) 45 { 46 this.dataBuffer = _dataBuffer; 47 } 48 49 protected boolean closed = false; 50 51 public void close() 52 throws IOException 53 { 54 if (closed) 55 return; 56 57 dataBuffer.closeOutputStream(); 58 closed = true; 59 } 60 61 public void flush() 62 throws IOException 63 { 64 if (closed) 65 throw new IOException ("OutputStream is already closed!"); 66 67 dataBuffer.flushOutputStream(); 68 } 69 70 public void write(byte[] b) 71 throws java.io.IOException 72 { 73 if (closed) 74 throw new IOException ("OutputStream is already closed!"); 75 76 dataBuffer.write(b, 0, b.length); 77 } 78 79 public void write(byte[] b, int off, int len) 80 throws IOException 81 { 82 if (closed) 83 throw new IOException ("OutputStream is already closed!"); 84 85 dataBuffer.write(b, off, len); 86 } 87 88 byte[] oneByteByteArray = null; 89 90 public void write(int b) 91 throws java.io.IOException 92 { 93 if (closed) 94 throw new IOException ("OutputStream is already closed!"); 95 96 if (oneByteByteArray == null) 97 oneByteByteArray = new byte[1]; 98 99 oneByteByteArray[0] = (byte)b; 100 dataBuffer.write(oneByteByteArray, 0, 1); 101 } 102 103 } | Popular Tags |