This {@code InputStream} reads input from some other given {@code InputStream}, and verifies checksums while reading. Its primary intended use is to verify log files that are being copied as part of a programmatic backup. It is critical that invalid files are not added to a backup set, since then both the live environment and the backup will be invalid.
The following example verifies log files as they are being copied. The {@link DbBackup} class should normally be used to obtain the array of filesto be copied.
void copyFiles(final Environment env, final String[] fileNames, final File destDir, final int bufSize) throws IOException, DatabaseException { final File srcDir = env.getHome(); for (final String fileName : fileNames) { final File destFile = new File(destDir, fileName); final FileOutputStream fos = new FileOutputStream(destFile); final File srcFile = new File(srcDir, fileName); final FileInputStream fis = new FileInputStream(srcFile); final LogVerificationInputStream vis = new LogVerificationInputStream(env, fis, fileName); final byte[] buf = new byte[bufSize]; try { while (true) { final int len = vis.read(buf); if (len < 0) { break; } fos.write(buf, 0, len); } } finally { fos.close(); vis.close(); } } }
It is important to call the {@link #close} method of the {@code LogVerificationInputStream} to detect incomplete entries at the end of thelog file.
Note that {@code mark} and {@code reset} are not supported and {@code markSupported} returns false. The default {@link InputStream}implementation of these methods is used.
@see DbBackup @see DbVerifyLog
|
|