{
sLogger.log(Level.FINE, "mbean.begin_download");
if (downloadInfo == null)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.call_preparedownload_first" );
throw new ControlException( msg );
}
else if (!downloadInfo.isPrepared)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.call_preparedownload_first" );
throw new ControlException( msg );
}
if ((chunkIndex >= downloadInfo.numChunks) || (chunkIndex < 0))
{
String msg = localStrings.getString( "admin.server.core.mbean.config.invalid_chunk_index" );
throw new ControlException( msg );
}
RandomAccessFile raf = null;
ByteChunk byteChunk = null;
try
{
raf = new RandomAccessFile(downloadInfo.downloadFile, "r");
byte[] bytes = new byte[ByteChunk.kChunkMaxSize];
raf.seek(downloadInfo.numBytesRead);
int actualBytesRead = raf.read(bytes, 0, ByteChunk.kChunkMaxSize);
/*
Debug.println("Read " + actualBytesRead + " from " +
downloadInfo.numBytesRead);
*/
if (actualBytesRead < bytes.length)
{
byte[] newBytes = new byte[actualBytesRead];
for (int i = 0; i < newBytes.length; i++)
{
newBytes[i] = bytes[i];
}
bytes = newBytes;
}
downloadInfo.numBytesRead += actualBytesRead;
boolean isFirstChunk = (chunkIndex == 0);
boolean isLastChunk =
(chunkIndex == (downloadInfo.numChunks - 1));
sLogger.log(Level.FINEST, "chunkIndex = " + chunkIndex +
" isFirstChunk = " + isFirstChunk +
" isLastChunk = " + isLastChunk);
byteChunk = new ByteChunk(bytes,
downloadInfo.downloadFile.getAbsolutePath(),
isFirstChunk, isLastChunk);
}
catch (Exception ioe)
{
sLogger.log(Level.FINE, "mbean.download_failed", ioe);
downloadInfo.reset();
try
{
lock.release();
}
catch (Exception e)
{
sLogger.log(Level.FINEST, "lock could not be released");
}
throw new ControlException(ioe.toString());
}
finally
{
if (raf != null)
{