bytesToRead = (int) lengthToWrite;
}
bytesHandled = inputStream.read(buffer, 0, bytesToRead);
if (bytesHandled == -1) {
throw new HandlerException("Cannot read all data from reference.");
}
dataOutputStream.write(buffer, 0, bytesHandled);
lengthToWrite -= bytesHandled;
position += bytesHandled;
}
dataOutputStream.flush();
} catch (IOException e) {
throw new HandlerException(e);
} finally {
try {
if (inputStream != null) {
inputStream.close();
inputStream = null;