You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/11/21 17:46:55 UTC

[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes

mdmarshmallow commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1028358333


##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.store;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IndexOutput implementation that delegates calls to another directory. This class can be used to
+ * add limitations on top of an existing {@link IndexOutput} implementation such as {@link
+ * ByteBuffersIndexOutput} or to add additional sanity checks for tests. However, if you plan to
+ * write your own {@link IndexOutput} implementation, you should consider extending directly {@link
+ * IndexOutput} or {@link DataOutput} rather than try to reuse functionality of existing {@link
+ * IndexOutput}s by extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexOutput extends IndexOutput {
+
+  public static IndexOutput unwrap(IndexOutput out) {
+    while (out instanceof FilterIndexOutput) {
+      out = ((FilterIndexOutput) out).out;
+    }
+    return out;
+  }
+
+  protected final IndexOutput out;
+
+  protected FilterIndexOutput(String resourceDescription, String name, IndexOutput out) {
+    super(resourceDescription, name);
+    this.out = out;
+  }
+
+  public final IndexOutput getDelegate() {
+    return out;
+  }
+
+  @Override
+  public void close() throws IOException {
+    out.close();
+  }
+
+  @Override
+  public long getFilePointer() {
+    return out.getFilePointer();
+  }
+
+  @Override
+  public long getChecksum() throws IOException {
+    return out.getChecksum();
+  }
+
+  @Override
+  public void writeByte(byte b) throws IOException {
+    out.writeByte(b);
+  }
+
+  @Override
+  public void writeBytes(byte[] b, int offset, int length) throws IOException {
+    out.writeBytes(b, offset, length);
+  }
+
+  @Override
+  public void writeBytes(byte[] b, int length) throws IOException {

Review Comment:
   Not sure if we want to call `out.writeBytes` here or `this.writeBytes` since this really is just a method overload for convenience and should share any overridden behavior with the other `writeBytes` function if it is overridden.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org