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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1383905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-09-12 12:15:51 +00:00
parent 1fe0640fcc
commit 2800989d4a
10 changed files with 9 additions and 114 deletions

View File

@ -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

View File

@ -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}
*/

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -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 {