List of usage examples for org.apache.lucene.store IOContext DEFAULT
IOContext DEFAULT
To view the source code for org.apache.lucene.store IOContext DEFAULT.
Click Source Link
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 o m 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.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 ww . j a va2 s . c o m*/ 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. j a 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.BaseDirectoryTestSuite.java
License:Apache License
private void createFile(String name, Directory fsDir, Directory hdfs) throws IOException { int writes = random.nextInt(MAX_NUMBER_OF_WRITES); int fileLength = random.nextInt(MAX_FILE_SIZE - MIN_FILE_SIZE) + MIN_FILE_SIZE; IndexOutput fsOutput = fsDir.createOutput(name, IOContext.DEFAULT); fsOutput.setLength(fileLength);/*w w w . jav a 2s .co m*/ IndexOutput hdfsOutput = hdfs.createOutput(name, IOContext.DEFAULT); hdfsOutput.setLength(fileLength); for (int i = 0; i < writes; i++) { byte[] buf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength)) + MIN_BUFFER_SIZE]; random.nextBytes(buf); int offset = random.nextInt(buf.length); int length = random.nextInt(buf.length - offset); fsOutput.writeBytes(buf, offset, length); hdfsOutput.writeBytes(buf, offset, length); } fsOutput.close(); hdfsOutput.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);//from w w w . j a va2s .c o m try { 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];//w w w . j a v a 2s . c o m 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.BlockDirectoryTest.java
License:Apache License
private void createFile(String name, Directory fsDir, Directory hdfs) throws IOException { int writes = random.nextInt(MAX_NUMBER_OF_WRITES); int fileLength = random.nextInt(MAX_FILE_SIZE - MIN_FILE_SIZE) + MIN_FILE_SIZE; IndexOutput fsOutput = fsDir.createOutput(name, IOContext.DEFAULT); IndexOutput hdfsOutput = hdfs.createOutput(name, IOContext.DEFAULT); for (int i = 0; i < writes; i++) { byte[] buf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength)) + MIN_BUFFER_SIZE];//from w ww .j a v a2 s. c om random.nextBytes(buf); int offset = random.nextInt(buf.length); int length = random.nextInt(buf.length - offset); fsOutput.writeBytes(buf, offset, length); hdfsOutput.writeBytes(buf, offset, length); } fsOutput.close(); hdfsOutput.close(); }
From source file:com.bah.lucene.blockcache_v2.CacheDirectoryTest.java
License:Apache License
@Test public void test1() throws IOException { IndexOutput output = _cacheDirectory.createOutput("test.file", IOContext.DEFAULT); output.writeLong(0);//w w w.ja v a 2s . c om output.writeLong(1); output.writeLong(2); output.close(); IndexInput input = _cacheDirectory.openInput("test.file", IOContext.DEFAULT); assertEquals(0, input.readLong()); assertEquals(1, input.readLong()); assertEquals(2, input.readLong()); input.close(); }
From source file:com.bah.lucene.blockcache_v2.CacheDirectoryTest.java
License:Apache License
@Test public void test2() throws IOException { IndexOutput output = _cacheDirectory.createOutput("test.file", IOContext.DEFAULT); byte[] buf = new byte[9000]; for (int i = 0; i < buf.length; i++) { buf[i] = (byte) i; }// w w w . j a v a 2 s . c om output.writeBytes(buf, buf.length); output.close(); IndexInput input = _cacheDirectory.openInput("test.file", IOContext.DEFAULT); assertEquals(9000, input.length()); input.close(); }
From source file:com.bah.lucene.blockcache_v2.CacheIndexInputTest.java
License:Apache License
@Test public void test1() throws IOException { RAMDirectory directory = new RAMDirectory(); String name = "test"; IndexOutput output = directory.createOutput(name, IOContext.DEFAULT); byte[] bs = "hello world".getBytes(); output.writeBytes(bs, bs.length);//from w w w . j av a 2 s.co m output.close(); IndexInput input = directory.openInput(name, IOContext.DEFAULT); Cache cache = getCache(); CacheIndexInput cacheInput = new CacheIndexInput(null, name, input, cache); byte[] buf = new byte[bs.length]; cacheInput.readBytes(buf, 0, buf.length); cacheInput.close(); assertArrayEquals(bs, buf); directory.close(); }