1 package com.quadcap.sql.file; 2 3 40 41 import java.io.IOException ; 42 import java.io.OutputStream ; 43 44 import com.quadcap.util.Debug; 45 import com.quadcap.util.Util; 46 47 52 public class RandomAccessOutputStream extends OutputStream { 53 RandomAccess ra; 54 int position; 55 byte[] buf = new byte[1]; 56 57 public RandomAccessOutputStream(RandomAccess ra) { 58 this.ra = ra; 59 this.position = 0; 60 } 61 62 public int getPosition() { return position; } 63 public void setPosition(int p) { position = p; } 64 public long size() { return ra.size(); } 65 public void resize(long size) throws IOException { 66 ra.resize(size); 67 } 68 69 78 public void write(int b) throws IOException { 79 buf[0] = (byte)b; 80 write(buf, 0, buf.length); 81 } 82 83 95 public void write(byte b[]) throws IOException { 96 write(b, 0, b.length); 97 } 98 99 113 public void write(byte b[], int off, int len) throws IOException { 114 if (position + len > ra.size()) ra.resize(position + len); 115 ra.write(position, b, off, len); 116 position += len; 117 } 118 119 129 public void flush() throws IOException { 130 } 131 132 140 public void close() throws IOException { 141 ra.close(); 142 } 143 } 144 | Popular Tags |