1 29 30 package com.caucho.db.store; 31 32 import java.io.IOException ; 33 import java.io.Reader ; 34 35 public class ClobReader extends Reader { 36 private static final int INODE_DIRECT_BLOCKS = 14; 37 38 private Store _store; 39 40 private long _length; 41 private long _offset; 42 43 private byte []_inode; 44 private int _inodeOffset; 45 46 private long _lastOffset; 47 private long _fragmentId; 48 49 private char []_buffer; 50 51 56 public ClobReader(Store store, byte []inode, int inodeOffset) 57 { 58 init(store, inode, inodeOffset); 59 } 60 61 66 public ClobReader(Inode inode) 67 { 68 init(inode.getStore(), inode.getBuffer(), 0); 69 } 70 71 74 public void init(Store store, byte []inode, int inodeOffset) 75 { 76 if (store == null) 77 throw new NullPointerException (); 78 79 _store = store; 80 81 _inode = inode; 82 _inodeOffset = inodeOffset; 83 84 _length = readLong(inode, inodeOffset); 85 _offset = 0; 86 87 _fragmentId = 0; 88 _lastOffset = 0; 89 } 90 91 94 public int read() 95 throws IOException 96 { 97 if (_buffer == null) 98 _buffer = new char[1]; 99 100 int len = read(_buffer, 0, 1); 101 102 if (len < 0) 103 return -1; 104 else 105 return _buffer[0]; 106 } 107 108 111 public int read(char []buf, int offset, int length) 112 throws IOException 113 { 114 int sublen = Inode.read(_inode, _inodeOffset, 115 _store, _offset, 116 buf, offset, length); 117 118 if (sublen > 0) 119 _offset += 2 * sublen; 120 121 return sublen; 122 } 123 124 127 public void close() 128 { 129 } 130 131 134 public static long readLong(byte []buffer, int offset) 135 { 136 return (((buffer[offset + 0] & 0xffL) << 56) + 137 ((buffer[offset + 1] & 0xffL) << 48) + 138 ((buffer[offset + 2] & 0xffL) << 40) + 139 ((buffer[offset + 3] & 0xffL) << 32) + 140 ((buffer[offset + 4] & 0xffL) << 24) + 141 ((buffer[offset + 5] & 0xffL) << 16) + 142 ((buffer[offset + 6] & 0xffL) << 8) + 143 ((buffer[offset + 7] & 0xffL))); 144 } 145 146 149 private static int readShort(byte []buffer, int offset) 150 { 151 return (((buffer[offset + 0] & 0xff) << 8) + 152 ((buffer[offset + 1] & 0xff))); 153 } 154 } 155 | Popular Tags |