Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17232: PropertiesOutputStream overrides write(byte[], int, int). (#2400)

Bruno Roustant5856581b3056
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bdb44b60dc0..21f11556661 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -205,6 +205,9 @@ Other Changes
* SOLR-17217: Simplify verbose MatcherAssert.assertThat usage in tests (hossman)
+* SOLR-17232: PropertiesOutputStream is renamed IndexOutputOutputStream and overrides write(byte[], int, int).
+ (Bruno Roustant)
+
================== 9.5.0 ==================
New Features
---------------------
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index c72d9debc55..2b1bd65f292 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -168,9 +168,9 @@ import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.update.processor.UpdateRequestProcessorChain.ProcessorInfo;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.util.IOFunction;
+import org.apache.solr.util.IndexOutputOutputStream;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.util.PropertiesInputStream;
-import org.apache.solr.util.PropertiesOutputStream;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TestInjection;
import org.apache.solr.util.circuitbreaker.CircuitBreaker;
@@ -1514,7 +1514,7 @@ public class SolrCore implements SolrInfoBean, Closeable {
Writer os = null;
try {
IndexOutput out = dir.createOutput(tmpFileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
- os = new OutputStreamWriter(new PropertiesOutputStream(out), StandardCharsets.UTF_8);
+ os = new OutputStreamWriter(new IndexOutputOutputStream(out), StandardCharsets.UTF_8);
p.store(os, IndexFetcher.INDEX_PROPERTIES);
dir.sync(Collections.singleton(tmpFileName));
} catch (Exception e) {
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index 4dbe9faf44b..b06353fcaeb 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -129,7 +129,7 @@ import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.security.AllowListUrlChecker;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.util.FileUtils;
-import org.apache.solr.util.PropertiesOutputStream;
+import org.apache.solr.util.IndexOutputOutputStream;
import org.apache.solr.util.RTimer;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TestInjection;
@@ -985,7 +985,7 @@ public class IndexFetcher {
String tmpFileName = REPLICATION_PROPERTIES + "." + System.nanoTime();
final IndexOutput out = dir.createOutput(tmpFileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
try (Writer outFile =
- new OutputStreamWriter(new PropertiesOutputStream(out), StandardCharsets.UTF_8)) {
+ new OutputStreamWriter(new IndexOutputOutputStream(out), StandardCharsets.UTF_8)) {
props.store(outFile, "Replication details");
dir.sync(Collections.singleton(tmpFileName));
}
diff --git a/solr/core/src/java/org/apache/solr/util/PropertiesOutputStream.java b/solr/core/src/java/org/apache/solr/util/IndexOutputOutputStream.java
similarity index 76%
rename from solr/core/src/java/org/apache/solr/util/PropertiesOutputStream.java
rename to solr/core/src/java/org/apache/solr/util/IndexOutputOutputStream.java
index bf840392cca..eec0ebac2e9 100644
--- a/solr/core/src/java/org/apache/solr/util/PropertiesOutputStream.java
+++ b/solr/core/src/java/org/apache/solr/util/IndexOutputOutputStream.java
@@ -20,11 +20,12 @@ import java.io.IOException;
import java.io.OutputStream;
import org.apache.lucene.store.IndexOutput;
-public class PropertiesOutputStream extends OutputStream {
+/** Wraps an {@link IndexOutput} to expose it as an {@link OutputStream}. */
+public class IndexOutputOutputStream extends OutputStream {
- private IndexOutput out;
+ private final IndexOutput out;
- public PropertiesOutputStream(IndexOutput out) {
+ public IndexOutputOutputStream(IndexOutput out) {
this.out = out;
}
@@ -33,9 +34,13 @@ public class PropertiesOutputStream extends OutputStream {
out.writeByte((byte) b);
}
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ out.writeBytes(b, off, len);
+ }
+
@Override
public void close() throws IOException {
- super.close();
out.close();
}
}