List of usage examples for org.apache.lucene.store IndexInput seek
public abstract void seek(long pos) throws IOException;
From source file:com.bah.lucene.BaseDirectoryTestSuite.java
License:Apache License
private void testEof(String name, Directory directory, long length) throws IOException { IndexInput input = directory.openInput(name, IOContext.DEFAULT); try {/*from w w w. jav a 2 s . c om*/ input.seek(length); input.readByte(); fail("should throw eof"); } catch (IOException e) { } }
From source file:com.bah.lucene.BaseDirectoryTestSuite.java
License:Apache License
private void assertInputsEquals(String name, Directory fsDir, Directory hdfs) throws IOException { int reads = random.nextInt(MAX_NUMBER_OF_READS); IndexInput fsInput = fsDir.openInput(name, IOContext.DEFAULT); IndexInput hdfsInput = hdfs.openInput(name, IOContext.DEFAULT); assertEquals(fsInput.length(), hdfsInput.length()); int fileLength = (int) fsInput.length(); for (int i = 0; i < reads; i++) { byte[] fsBuf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength)) + MIN_BUFFER_SIZE];//from w w w . ja v a 2 s.c om byte[] hdfsBuf = new byte[fsBuf.length]; int offset = random.nextInt(fsBuf.length); int length = random.nextInt(fsBuf.length - offset); int pos = random.nextInt(fileLength - length); fsInput.seek(pos); fsInput.readBytes(fsBuf, offset, length); hdfsInput.seek(pos); hdfsInput.readBytes(hdfsBuf, offset, length); for (int f = offset; f < length; f++) { if (fsBuf[f] != hdfsBuf[f]) { fail(); } } } fsInput.close(); hdfsInput.close(); }
From source file:com.bah.lucene.blockcache.BlockDirectoryTest.java
License:Apache License
private void testEof(String name, Directory directory, long length) throws IOException { IndexInput input = directory.openInput(name, IOContext.DEFAULT); input.seek(length); try {/*from w w w . j a v a2s .co m*/ input.readByte(); fail("should throw eof"); } catch (IOException e) { } }
From source file:com.bah.lucene.blockcache.BlockDirectoryTest.java
License:Apache License
private void assertInputsEquals(String name, Directory fsDir, Directory hdfs) throws IOException { int reads = random.nextInt(MAX_NUMBER_OF_READS); IndexInput fsInput = fsDir.openInput(name, IOContext.DEFAULT); IndexInput hdfsInput = hdfs.openInput(name, IOContext.DEFAULT); assertEquals(fsInput.length(), hdfsInput.length()); int fileLength = (int) fsInput.length(); if (fileLength != 0) { for (int i = 0; i < reads; i++) { byte[] fsBuf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength)) + MIN_BUFFER_SIZE];//from w w w.j a va 2 s . com byte[] hdfsBuf = new byte[fsBuf.length]; int offset = random.nextInt(fsBuf.length); int length = random.nextInt(fsBuf.length - offset); int pos = random.nextInt(fileLength - length); fsInput.seek(pos); fsInput.readBytes(fsBuf, offset, length); hdfsInput.seek(pos); hdfsInput.readBytes(hdfsBuf, offset, length); for (int f = offset; f < length; f++) { if (fsBuf[f] != hdfsBuf[f]) { fail(Long.toString(seed) + " read [" + i + "]"); } } } } fsInput.close(); hdfsInput.close(); }
From source file:com.bah.lucene.blockcache_v2.CacheIndexInputTest.java
License:Apache License
public static void readRandomData(IndexInput baseInput, IndexInput testInput, Random random, int sampleSize, int maxBufSize, int maxOffset) throws IOException { assertEquals(baseInput.length(), testInput.length()); int fileLength = (int) baseInput.length(); for (int i = 0; i < sampleSize; i++) { int position = random.nextInt(fileLength - maxBufSize); int bufSize = random.nextInt(maxBufSize - maxOffset) + 1; byte[] buf1 = new byte[bufSize]; byte[] buf2 = new byte[bufSize]; int offset = random.nextInt(Math.min(maxOffset, bufSize)); int len = Math.min(random.nextInt(bufSize - offset), fileLength - position); baseInput.seek(position); baseInput.readBytes(buf1, offset, len); testInput.seek(position);//from w w w .j ava2 s. co m testInput.readBytes(buf2, offset, len); assertArrayEquals("Read [" + i + "] The position is [" + position + "] and bufSize [" + bufSize + "]", buf1, buf2); } }
From source file:com.bah.lucene.blockcache_v2.CacheIndexInputTest.java
License:Apache License
public static void readRandomDataInt(IndexInput baseInput, IndexInput testInput, Random random, int sampleSize) throws IOException { assertEquals(baseInput.length(), testInput.length()); int fileLength = (int) baseInput.length(); for (int i = 0; i < sampleSize; i++) { int position = random.nextInt(fileLength - 4); baseInput.seek(position); int i1 = baseInput.readInt(); testInput.seek(position);// www . j a va 2 s. co m int i2 = testInput.readInt(); assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2); } }
From source file:com.bah.lucene.blockcache_v2.CacheIndexInputTest.java
License:Apache License
public static void readRandomDataShort(IndexInput baseInput, IndexInput testInput, Random random, int sampleSize) throws IOException { assertEquals(baseInput.length(), testInput.length()); int fileLength = (int) baseInput.length(); for (int i = 0; i < sampleSize; i++) { int position = random.nextInt(fileLength - 2); baseInput.seek(position); short i1 = baseInput.readShort(); testInput.seek(position);/*from www. j a v a2 s . c o m*/ short i2 = testInput.readShort(); assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2); } }
From source file:com.bah.lucene.blockcache_v2.CacheIndexInputTest.java
License:Apache License
public static void readRandomDataLong(IndexInput baseInput, IndexInput testInput, Random random, int sampleSize) throws IOException { assertEquals(baseInput.length(), testInput.length()); int fileLength = (int) baseInput.length(); for (int i = 0; i < sampleSize; i++) { int position = random.nextInt(fileLength - 8); baseInput.seek(position); long i1 = baseInput.readLong(); testInput.seek(position);//w w w. j ava 2s. co m long i2 = testInput.readLong(); assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2); } }
From source file:com.github.lucene.store.jdbc.index.AbstractIndexInputOutputITest.java
License:Apache License
private void verifyData() throws IOException { final byte[] test = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Assert.assertTrue(jdbcDirectory.fileExists("value1")); Assert.assertEquals(36, jdbcDirectory.fileLength("value1")); final IndexInput indexInput = jdbcDirectory.openInput("value1", new IOContext()); Assert.assertEquals(-1, indexInput.readInt()); Assert.assertEquals(10, indexInput.readLong()); Assert.assertEquals(0, indexInput.readInt()); Assert.assertEquals(0, indexInput.readInt()); indexInput.readBytes(test, 0, 8);//from w ww . jav a 2 s. co m Assert.assertEquals((byte) 1, test[0]); Assert.assertEquals((byte) 8, test[7]); indexInput.readBytes(test, 0, 5); Assert.assertEquals((byte) 1, test[0]); Assert.assertEquals((byte) 5, test[4]); indexInput.seek(28); Assert.assertEquals((byte) 1, indexInput.readByte()); indexInput.seek(30); Assert.assertEquals((byte) 3, indexInput.readByte()); indexInput.close(); }
From source file:com.lucure.core.codec.ForUtil.java
License:Apache License
/** * Skip the next block of data./* w w w . j a va 2s .c om*/ * * @param in the input where to read data * @throws IOException If there is a low-level I/O error */ void skipBlock(IndexInput in) throws IOException { final int numBits = in.readByte(); if (numBits == ALL_VALUES_EQUAL) { in.readVInt(); return; } assert numBits > 0 && numBits <= 32 : numBits; final int encodedSize = encodedSizes[numBits]; in.seek(in.getFilePointer() + encodedSize); }