Github user dweiss commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/432#discussion_r209172193
--- Diff:
lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java ---
@@ -0,0 +1,237 @@
+package org.apache.lucene.store;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.file.AccessDeniedException;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.NoSuchFileException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.zip.CRC32;
+
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.util.BitUtil;
+
+public final class ByteBuffersDirectory extends BaseDirectory {
+ public static final BiFunction<String, ByteBuffersDataOutput,
IndexInput> OUTPUT_AS_MANY_BUFFERS =
+ (fileName, output) -> {
+ ByteBuffersDataInput dataInput = output.toDataInput();
+ String inputName = String.format(Locale.ROOT, "%s (file=%s,
buffers=%s)",
+ ByteBuffersIndexInput.class.getSimpleName(),
+ fileName,
+ dataInput.toString());
+ return new ByteBuffersIndexInput(dataInput, inputName);
+ };
+
+ public static final BiFunction<String, ByteBuffersDataOutput,
IndexInput> OUTPUT_AS_ONE_BUFFER =
+ (fileName, output) -> {
+ ByteBuffersDataInput dataInput = new
ByteBuffersDataInput(Arrays.asList(ByteBuffer.wrap(output.copyToArray())));
+ String inputName = String.format(Locale.ROOT, "%s (file=%s,
buffers=%s)",
+ ByteBuffersIndexInput.class.getSimpleName(),
+ fileName,
+ dataInput.toString());
+ return new ByteBuffersIndexInput(dataInput, inputName);
+ };
+
+ public static final BiFunction<String, ByteBuffersDataOutput,
IndexInput> OUTPUT_AS_BYTE_ARRAY =
+ (fileName, output) -> {
+ byte[] array = output.copyToArray();
+ String inputName = String.format(Locale.ROOT, "%s (file=%s,
length=%s)",
+ ByteArrayIndexInput.class.getSimpleName(),
+ fileName,
+ array.length);
+ return new ByteArrayIndexInput(inputName, array, 0, array.length);
+ };
+
+ public static final BiFunction<String, ByteBuffersDataOutput,
IndexInput> OUTPUT_AS_MANY_BUFFERS_LUCENE =
+ (fileName, output) -> {
+ List<ByteBuffer> bufferList = output.toBufferList();
+ int chunkSizePower;
+ bufferList.add(ByteBuffer.allocate(0));
--- End diff --
I know -- it's the wraparound case in case pos falls just outside of the
block boundary. Simplifies some logic later on, I think it's harmless.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]