throw new IOException("cannot read directory " + src + ": list() returned null");
byte[] buf = new byte[BufferedIndexOutput.getBufSize()];
for (int i = 0; i < files.length; i++) {
IndexOutput os = null;
IndexInput is = null;
try {
// create file in dest directory
os = dest.createOutput(files[i]);
// read current file
is = src.openInput(files[i]);
// and copy to dest directory
long len = is.length();
long readCount = 0;
while (readCount < len) {
int toRead = readCount + BufferedIndexOutput.getBufSize() > len ? (int)(len - readCount) : BufferedIndexOutput.getBufSize();
is.readBytes(buf, 0, toRead);
os.writeBytes(buf, toRead);
readCount += toRead;
}
} finally {
// graceful cleanup
try {
if (os != null)
os.close();
} finally {
if (is != null)
is.close();
}
}
}
if(closeDirSrc)
src.close();