< prev index next >
apps/samples/Ensemble8/src/app/java/ensemble/search/ClasspathDirectory.java
Print this page
rev 9898 : 8178275: Ensemble: Upgrade version of Lucene to 7.1.0
Reviewed-by: aghaisas, prr
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2008, 2014, Oracle and/or its affiliates.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
@@ -34,16 +34,19 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.store.Lock;
/**
* A very simple implementation of lucene Directory, it reads a index from the classpath in a directory called index
* under the package that contains this file. It depends on a "listAll.txt" file written into that directory containing
* the names of all the other files and their sizes. In the format "name:length" one file per line. When a file needs
@@ -73,23 +76,25 @@
@Override public String[] listAll() throws IOException {
return allFiles;
}
- @Override public IndexInput openInput(String s) throws IOException {
+ @Override public IndexInput openInput(String s, IOContext ioc) throws IOException {
return new ClassPathIndexInput(
+ s,
getClass().getResourceAsStream("index/"+s),
fileLengthMap.get(s).intValue()
);
}
private static class ClassPathIndexInput extends IndexInput {
private byte[] data;
private int pointer = 0;
private int length;
- private ClassPathIndexInput(InputStream in, int length) throws IOException {
+ private ClassPathIndexInput(String resourceDescription, InputStream in, int length) throws IOException {
+ super(resourceDescription);
this.length = length;
// read whole file into memory, so we can provide random access
data = new byte[length];
// read in upto 20k chunks
// this is needed as the amount of bytes read in any call in not
@@ -106,10 +111,17 @@
}
} while (read != -1 && remaining > 0);
in.close();
}
+ private ClassPathIndexInput(String resourceDescription, byte[] data) {
+ super(resourceDescription);
+ this.data = data;
+ this.pointer = 0;
+ this.length = data.length;
+ }
+
@Override public byte readByte() throws IOException {
return data[pointer ++];
}
@Override public void readBytes(byte[] bytes, int offset, int len) throws IOException {
@@ -122,15 +134,50 @@
@Override public long getFilePointer() { return pointer; }
@Override public void seek(long l) throws IOException { pointer = (int)l; }
@Override public long length() { return length; }
+
+ @Override
+ public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
+ int o = (int) offset;
+ int l = (int) length;
+ byte[] sliceData = new byte[l];
+ System.arraycopy(data, o, sliceData, 0, l);
+ return new ClassPathIndexInput(sliceDescription, sliceData);
+ }
}
@Override public void close() throws IOException {}
- @Override public boolean fileExists(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
- @Override public long fileModified(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
- @Override @Deprecated public void touchFile(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
@Override public void deleteFile(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
@Override public long fileLength(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
- @Override public IndexOutput createOutput(String s) throws IOException { throw new UnsupportedOperationException("Not implemented"); }
+ @Override
+ public IndexOutput createOutput(String string, IOContext ioc) throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public IndexOutput createTempOutput(String string, String string1, IOContext ioc) throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public void sync(Collection<String> clctn) throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public void rename(String string, String string1) throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public void syncMetaData() throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public Lock obtainLock(String string) throws IOException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
}
< prev index next >