List of usage examples for org.apache.lucene.store IndexInput readInt
public int readInt() throws IOException
From source file:com.bah.lucene.BaseDirectoryTestSuite.java
License:Apache License
@Test public void testWritingAndReadingAFile() throws IOException { IndexOutput output = directory.createOutput("testing.test", IOContext.DEFAULT); output.writeInt(12345);// w w w . j av a2 s . c om output.flush(); output.close(); IndexInput input = directory.openInput("testing.test", IOContext.DEFAULT); assertEquals(12345, input.readInt()); input.close(); String[] listAll = directory.listAll(); assertEquals(1, listAll.length); assertEquals("testing.test", listAll[0]); assertEquals(4, directory.fileLength("testing.test")); IndexInput input1 = directory.openInput("testing.test", IOContext.DEFAULT); IndexInput input2 = (IndexInput) input1.clone(); assertEquals(12345, input2.readInt()); input2.close(); assertEquals(12345, input1.readInt()); input1.close(); assertFalse(directory.fileExists("testing.test.other")); assertTrue(directory.fileExists("testing.test")); directory.deleteFile("testing.test"); assertFalse(directory.fileExists("testing.test")); }
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);/*ww w . j a v a2s . c o m*/ int i1 = baseInput.readInt(); testInput.seek(position); int i2 = testInput.readInt(); assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2); } }
From source file:com.browseengine.bobo.geosearch.solo.impl.IDGeoRecordSerializer.java
License:Apache License
@Override public IDGeoRecord readGeoRecord(IndexInput input, int recordByteCount) throws IOException { long highOrder = input.readLong(); int lowOrder = input.readInt(); int countIdBytes = recordByteCount - INTERLACE_BYTES; byte[] id = new byte[countIdBytes]; input.readBytes(id, 0, countIdBytes, false); return new IDGeoRecord(highOrder, lowOrder, id); }
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 ww w .j av a 2 s . c o 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.nearinfinity.bloomfilter.bitset.ThreadSafeBitSet.java
License:Apache License
@Override public void read(IndexInput input) throws IOException { int length = input.readInt(); bits = new AtomicLongArray(length); for (int i = 0; i < length; i++) { bits.set(i, input.readLong());/* w w w. j a v a2 s . c o m*/ } }
From source file:com.nearinfinity.bloomfilter.BloomFilter.java
License:Apache License
public void read(IndexInput input) throws IOException { numberOfBitsDivBy2 = input.readLong(); elementSize = input.readLong();/*ww w . ja v a2 s . c o m*/ probabilityOfFalsePositives = Double.longBitsToDouble(input.readLong()); hashes = input.readInt(); numberOfBits = input.readInt(); bitSet = new ThreadSafeBitSet(); bitSet.read(input); }
From source file:com.sindicetech.siren.index.codecs.siren10.Siren10PostingsReader.java
License:Open Source License
@Override public void init(final IndexInput termsIn) throws IOException { // Make sure we are talking to the matching past writer CodecUtil.checkHeader(termsIn, Siren10PostingsWriter.CODEC, Siren10PostingsWriter.VERSION_START, Siren10PostingsWriter.VERSION_CURRENT); blockSkipInterval = termsIn.readInt(); maxSkipLevels = termsIn.readInt();/*w w w. j a va 2 s . c o m*/ blockSkipMinimum = termsIn.readInt(); maxBlockSize = termsIn.readInt(); }
From source file:org.apache.blur.lucene.codec.Blur022SegmentInfoReader.java
License:Apache License
@Override public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException { final String fileName = IndexFileNames.segmentFileName(segment, "", Blur022SegmentInfoFormat.SI_EXTENSION); final IndexInput input = dir.openInput(fileName, context); boolean success = false; try {/*from www.j a v a 2 s . c o m*/ CodecUtil.checkHeader(input, Blur022SegmentInfoFormat.CODEC_NAME, Blur022SegmentInfoFormat.VERSION_START, Blur022SegmentInfoFormat.VERSION_CURRENT); final String version = input.readString(); final int docCount = input.readInt(); if (docCount < 0) { throw new CorruptIndexException("invalid docCount: " + docCount + " (resource=" + input + ")"); } final boolean isCompoundFile = input.readByte() == SegmentInfo.YES; final Map<String, String> diagnostics = input.readStringStringMap(); final Map<String, String> attributes = input.readStringStringMap(); final Set<String> files = input.readStringSet(); if (input.getFilePointer() != input.length()) { throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")"); } final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, Collections.unmodifiableMap(attributes)); si.setFiles(files); success = true; return si; } finally { if (!success) { IOUtils.closeWhileHandlingException(input); } else { input.close(); } } }
From source file:org.apache.blur.store.hdfs.MultiInstancesHdfsDirectoryTest.java
License:Apache License
@Test public void testMultiInstancesHdfsDirectoryTest1() throws IOException, InterruptedException { HdfsDirectory dir1 = new HdfsDirectory(_configuration, new Path(_root, "dir")); IndexOutput output = dir1.createOutput("a", IOContext.DEFAULT); output.writeInt(1234);/* ww w . j a v a 2s .c om*/ output.close(); HdfsDirectory dir2 = new HdfsDirectory(_configuration, new Path(_root, "dir")); IndexInput input = dir2.openInput("a", IOContext.READ); assertEquals(4, input.length()); assertEquals(1234, input.readInt()); input.close(); dir1.close(); dir2.close(); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectoryTest.java
License:Apache License
private void assertClosed(IndexInput input) throws IOException { try {/* ww w. j av a 2 s .c o m*/ input.length(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.seek(0); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.getFilePointer(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readInt(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readShort(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readLong(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readByte(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readString(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readStringSet(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readStringStringMap(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readVInt(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readVLong(); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readBytes(null, 0, 0); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } try { input.readBytes(null, 0, 0, false); fail("cannot use IndexInput once closed"); } catch (AlreadyClosedException e) { // expected exception } }