1 package org.apache.lucene.store; 2 3 18 19 import java.io.IOException ; 20 21 26 public abstract class IndexOutput { 27 28 31 public abstract void writeByte(byte b) throws IOException ; 32 33 38 public abstract void writeBytes(byte[] b, int length) throws IOException ; 39 40 43 public void writeInt(int i) throws IOException { 44 writeByte((byte)(i >> 24)); 45 writeByte((byte)(i >> 16)); 46 writeByte((byte)(i >> 8)); 47 writeByte((byte) i); 48 } 49 50 55 public void writeVInt(int i) throws IOException { 56 while ((i & ~0x7F) != 0) { 57 writeByte((byte)((i & 0x7f) | 0x80)); 58 i >>>= 7; 59 } 60 writeByte((byte)i); 61 } 62 63 66 public void writeLong(long i) throws IOException { 67 writeInt((int) (i >> 32)); 68 writeInt((int) i); 69 } 70 71 76 public void writeVLong(long i) throws IOException { 77 while ((i & ~0x7F) != 0) { 78 writeByte((byte)((i & 0x7f) | 0x80)); 79 i >>>= 7; 80 } 81 writeByte((byte)i); 82 } 83 84 87 public void writeString(String s) throws IOException { 88 int length = s.length(); 89 writeVInt(length); 90 writeChars(s, 0, length); 91 } 92 93 99 public void writeChars(String s, int start, int length) 100 throws IOException { 101 final int end = start + length; 102 for (int i = start; i < end; i++) { 103 final int code = (int)s.charAt(i); 104 if (code >= 0x01 && code <= 0x7F) 105 writeByte((byte)code); 106 else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0) { 107 writeByte((byte)(0xC0 | (code >> 6))); 108 writeByte((byte)(0x80 | (code & 0x3F))); 109 } else { 110 writeByte((byte)(0xE0 | (code >>> 12))); 111 writeByte((byte)(0x80 | ((code >> 6) & 0x3F))); 112 writeByte((byte)(0x80 | (code & 0x3F))); 113 } 114 } 115 } 116 117 118 public abstract void flush() throws IOException ; 119 120 121 public abstract void close() throws IOException ; 122 123 127 public abstract long getFilePointer(); 128 129 132 public abstract void seek(long pos) throws IOException ; 133 134 135 public abstract long length() throws IOException ; 136 137 138 } 139 | Popular Tags |