// Open them all for reading.
fileInputStreams = new FileInputStream[fileSet.length];
if (fileSet.length == 0)
{
throw new StoreException("There are no BDB log files to backup in the " + fromdir + " directory.");
}
for (int i = 0; i < fileSet.length; i++)
{
try
{
fileInputStreams[i] = new FileInputStream(fileSet[i]);
}
catch (FileNotFoundException e)
{
// Close any files opened for reading so far.
for (int j = 0; j < i; j++)
{
if (fileInputStreams[j] != null)
{
try
{
fileInputStreams[j].close();
}
catch (IOException ioEx)
{
// Rethrow this as a runtime exception, as something strange has happened.
throw new StoreException(ioEx);
}
}
}
// Could not open a consistent file set so try again.
break;
}
// A consistent set has been opened if all files were sucesfully opened for reading.
if (i == (fileSet.length - 1))
{
consistentSet = true;
}
}
// Check that the script has not timed out, and raise an error if it has.
long now = System.currentTimeMillis();
if ((now - start) > TIMEOUT)
{
throw new StoreException("Hot backup script failed to complete in " + (TIMEOUT / 1000) + " seconds.");
}
}
// Copy the consistent set of open files.
List<String> backedUpFileNames = new LinkedList<String>();
for (int j = 0; j < fileSet.length; j++)
{
File destFile = new File(todir + File.separator + fileSet[j].getName());
try
{
FileUtils.copy(fileSet[j], destFile);
}
catch (RuntimeException re)
{
Throwable cause = re.getCause();
if ((cause != null) && (cause instanceof IOException))
{
throw new StoreException(re.getMessage() + " fromDir:" + fromdir + " toDir:" + toDirFile, cause);
}
else
{
throw re;
}
}
backedUpFileNames.add(destFile.getName());
// Close all of the files.
try
{
fileInputStreams[j].close();
}
catch (IOException e)
{
// Rethrow this as a runtime exception, as something strange has happened.
throw new StoreException(e);
}
}
return backedUpFileNames.toArray(new String[backedUpFileNames.size()]);
}