1 package org.apache.lucene.store; 2 3 18 19 import java.io.IOException ; 20 21 25 public abstract class IndexInput implements Cloneable { 26 private char[] chars; 28 31 public abstract byte readByte() throws IOException ; 32 33 39 public abstract void readBytes(byte[] b, int offset, int len) 40 throws IOException ; 41 42 45 public int readInt() throws IOException { 46 return ((readByte() & 0xFF) << 24) | ((readByte() & 0xFF) << 16) 47 | ((readByte() & 0xFF) << 8) | (readByte() & 0xFF); 48 } 49 50 55 public int readVInt() throws IOException { 56 byte b = readByte(); 57 int i = b & 0x7F; 58 for (int shift = 7; (b & 0x80) != 0; shift += 7) { 59 b = readByte(); 60 i |= (b & 0x7F) << shift; 61 } 62 return i; 63 } 64 65 68 public long readLong() throws IOException { 69 return (((long)readInt()) << 32) | (readInt() & 0xFFFFFFFFL); 70 } 71 72 75 public long readVLong() throws IOException { 76 byte b = readByte(); 77 long i = b & 0x7F; 78 for (int shift = 7; (b & 0x80) != 0; shift += 7) { 79 b = readByte(); 80 i |= (b & 0x7FL) << shift; 81 } 82 return i; 83 } 84 85 88 public String readString() throws IOException { 89 int length = readVInt(); 90 if (chars == null || length > chars.length) 91 chars = new char[length]; 92 readChars(chars, 0, length); 93 return new String (chars, 0, length); 94 } 95 96 102 public void readChars(char[] buffer, int start, int length) 103 throws IOException { 104 final int end = start + length; 105 for (int i = start; i < end; i++) { 106 byte b = readByte(); 107 if ((b & 0x80) == 0) 108 buffer[i] = (char)(b & 0x7F); 109 else if ((b & 0xE0) != 0xE0) { 110 buffer[i] = (char)(((b & 0x1F) << 6) 111 | (readByte() & 0x3F)); 112 } else 113 buffer[i] = (char)(((b & 0x0F) << 12) 114 | ((readByte() & 0x3F) << 6) 115 | (readByte() & 0x3F)); 116 } 117 } 118 119 120 public abstract void close() throws IOException ; 121 122 126 public abstract long getFilePointer(); 127 128 131 public abstract void seek(long pos) throws IOException ; 132 133 134 public abstract long length(); 135 136 145 public Object clone() { 146 IndexInput clone = null; 147 try { 148 clone = (IndexInput)super.clone(); 149 } catch (CloneNotSupportedException e) {} 150 151 clone.chars = null; 152 153 return clone; 154 } 155 156 } 157 | Popular Tags |