Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-4377: Remove IndexInput.copyBytes(IndexOutput, long)

Robert Muir2800989d4a40
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f7ea4e1614f..54f55f69a75 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -99,6 +99,10 @@ API Changes
not be overriden by subclasses: per-stream initialization should happen
in reset(). (Robert Muir)
+* LUCENE-4377: Remove IndexInput.copyBytes(IndexOutput, long).
+ Use DataOutput.copyBytes(DataInput, long) instead.
+ (Mike McCandless, Robert Muir)
+
Bug Fixes
* LUCENE-4297: BooleanScorer2 would multiply the coord() factor
diff --git a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
index e972f2975bc..a59fb67ead8 100644
--- a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
@@ -338,18 +338,6 @@ public abstract class BufferedIndexInput extends IndexInput {
return toCopy;
}
- @Override
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- assert numBytes >= 0: "numBytes=" + numBytes;
-
- while (numBytes > 0) {
- if (bufferLength == bufferPosition) {
- refill();
- }
- numBytes -= flushBuffer(out, numBytes);
- }
- }
-
/**
* Returns default buffer sizes for the given {@link IOContext}
*/
diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java
index a08e83941c4..8313ef2cc7c 100644
--- a/lucene/core/src/java/org/apache/lucene/store/Directory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java
@@ -197,7 +197,7 @@ public abstract class Directory implements Closeable {
try {
os = to.createOutput(dest, context);
is = openInput(src, context);
- is.copyBytes(os, is.length());
+ os.copyBytes(is, is.length());
} catch (IOException ioe) {
priorException = ioe;
} finally {
@@ -314,22 +314,5 @@ public abstract class Directory implements Closeable {
public long length() {
return length;
}
-
- @Override
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- // Copy first whatever is in the buffer
- numBytes -= flushBuffer(out, numBytes);
-
- // If there are more bytes left to copy, delegate the copy task to the
- // base IndexInput, in case it can do an optimized copy.
- if (numBytes > 0) {
- long start = getFilePointer();
- if (start + numBytes > length) {
- throw new EOFException("read past EOF: " + this);
- }
- base.seek(fileOffset + start);
- base.copyBytes(out, numBytes);
- }
- }
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/IndexInput.java b/lucene/core/src/java/org/apache/lucene/store/IndexInput.java
index 60bb2f349a9..c864ceb0f71 100644
--- a/lucene/core/src/java/org/apache/lucene/store/IndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/IndexInput.java
@@ -66,30 +66,6 @@ public abstract class IndexInput extends DataInput implements Cloneable,Closeabl
/** The number of bytes in the file. */
public abstract long length();
- /**
- * Copies <code>numBytes</code> bytes to the given {@link IndexOutput}.
- * <p>
- * <b>NOTE:</b> this method uses an intermediate buffer to copy the bytes.
- * Consider overriding it in your implementation, if you can make a better,
- * optimized copy.
- * <p>
- * <b>NOTE</b> ensure that there are enough bytes in the input to copy to
- * output. Otherwise, different exceptions may be thrown, depending on the
- * implementation.
- */
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- assert numBytes >= 0: "numBytes=" + numBytes;
-
- byte copyBuf[] = new byte[BufferedIndexInput.BUFFER_SIZE];
-
- while (numBytes > 0) {
- final int toCopy = (int) (numBytes > copyBuf.length ? copyBuf.length : numBytes);
- readBytes(copyBuf, 0, toCopy);
- out.writeBytes(copyBuf, 0, toCopy);
- numBytes -= toCopy;
- }
- }
-
@Override
public String toString() {
return resourceDescription;
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index 48d63e428fb..86bc27ef9a0 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -300,7 +300,7 @@ public class NRTCachingDirectory extends Directory {
IndexInput in = null;
try {
in = cache.openInput(fileName, context);
- in.copyBytes(out, in.length());
+ out.copyBytes(in, in.length());
} finally {
IOUtils.close(in, out);
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java b/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java
index fa2fd5f713a..ba7cc4e3dd0 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java
@@ -105,27 +105,6 @@ public class RAMInputStream extends IndexInput implements Cloneable {
}
}
- @Override
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- assert numBytes >= 0: "numBytes=" + numBytes;
-
- long left = numBytes;
- while (left > 0) {
- if (bufferPosition == bufferLength) {
- ++currentBufferIndex;
- switchCurrentBuffer(true);
- }
-
- final int bytesInBuffer = bufferLength - bufferPosition;
- final int toCopy = (int) (bytesInBuffer < left ? bytesInBuffer : left);
- out.writeBytes(currentBuffer, bufferPosition, toCopy);
- bufferPosition += toCopy;
- left -= toCopy;
- }
-
- assert left == 0: "Insufficient bytes to copy: numBytes=" + numBytes + " copied=" + (numBytes - left);
- }
-
@Override
public long getFilePointer() {
return currentBufferIndex < 0 ? 0 : bufferStart + bufferPosition;
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
index c7eceaed843..1dc7014b513 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
@@ -178,27 +178,5 @@ public class RAMOutputStream extends IndexOutput {
/** Returns byte usage of all buffers. */
public long sizeInBytes() {
return (long) file.numBuffers() * (long) BUFFER_SIZE;
- }
-
- @Override
- public void copyBytes(DataInput input, long numBytes) throws IOException {
- assert numBytes >= 0: "numBytes=" + numBytes;
-
- while (numBytes > 0) {
- if (bufferPosition == bufferLength) {
- currentBufferIndex++;
- switchCurrentBuffer();
- }
-
- int toCopy = currentBuffer.length - bufferPosition;
- if (numBytes < toCopy) {
- toCopy = (int) numBytes;
- }
- input.readBytes(currentBuffer, bufferPosition, toCopy, false);
- numBytes -= toCopy;
- bufferPosition += toCopy;
- }
-
- }
-
+ }
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
index f5e01e3ed92..2600a0b172e 100644
--- a/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
@@ -208,12 +208,5 @@ public class SimpleFSDirectory extends FSDirectory {
boolean isFDValid() throws IOException {
return file.getFD().valid();
}
-
- @Override
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- numBytes -= flushBuffer(out, numBytes);
- // If out is FSIndexOutput, the copy will be optimized
- out.copyBytes(this, numBytes);
- }
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestCopyBytes.java b/lucene/core/src/test/org/apache/lucene/store/TestCopyBytes.java
index d8e870f54a3..69eaa6a1264 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestCopyBytes.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestCopyBytes.java
@@ -121,7 +121,7 @@ public class TestCopyBytes extends LuceneTestCase {
IndexInput input = d.openInput("data", IOContext.DEFAULT);
IndexOutput outputHeader = d.createOutput("header", IOContext.DEFAULT);
// copy our 100-byte header
- input.copyBytes(outputHeader, 100);
+ outputHeader.copyBytes(input, 100);
outputHeader.close();
// now make N copies of the remaining bytes
@@ -163,7 +163,7 @@ public class TestCopyBytes extends LuceneTestCase {
@Override
public void run() {
try {
- src.copyBytes(dst, src.length()-100);
+ dst.copyBytes(src, src.length()-100);
dst.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
index 09f91222c3c..a0bbedcd3ce 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
@@ -118,12 +118,6 @@ public class MockIndexInputWrapper extends IndexInput {
delegate.readBytes(b, offset, len);
}
- @Override
- public void copyBytes(IndexOutput out, long numBytes) throws IOException {
- ensureOpen();
- delegate.copyBytes(out, numBytes);
- }
-
@Override
public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
throws IOException {