public class LogVerificationInputStream
extends java.io.InputStream
InputStream for a log file in a JE
Environment.
This InputStream reads input from some other given 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
DbBackup class should normally be used to obtain the array of files
to 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 read the entire underlying input stream until the end-of-file is reached to detect incomplete entries at the end of the log file.
Note that mark and reset are not supported and markSupported returns false. The default InputStream
implementation of these methods is used.
DbBackup,
DbVerifyLog| Constructor and Description |
|---|
LogVerificationInputStream(Environment env,
java.io.InputStream in,
java.lang.String fileName)
Creates a verification input stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
long |
skip(long bytesToSkip) |
public LogVerificationInputStream(Environment env, java.io.InputStream in, java.lang.String fileName)
env - the Environment associated with the log.in - the underlying InputStream for the log to be read.fileName - the file name of the input stream, for reporting in the
LogVerificationException. This should be a simple file name of
the form NNNNNNNN.jdb, where NNNNNNNN is the file number in
hexadecimal format.EnvironmentFailureException - if an unexpected, internal or
environment-wide failure occurs.public int read()
throws java.io.IOException
This method reads the underlying InputStream and verifies the
contents of the stream.
read in class java.io.InputStreamLogVerificationException - if a checksum cannot be verified or a
log entry is determined to be invalid by examining its contents.EnvironmentFailureException - if an unexpected, internal or
environment-wide failure occurs.java.io.IOExceptionpublic int read(byte[] b)
throws java.io.IOException
This method reads the underlying InputStream and verifies the
contents of the stream.
read in class java.io.InputStreamLogVerificationException - if a checksum cannot be verified or a
log entry is determined to be invalid by examining its contents.EnvironmentFailureException - if an unexpected, internal or
environment-wide failure occurs.java.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
This method reads the underlying InputStream and verifies the
contents of the stream.
read in class java.io.InputStreamLogVerificationException - if a checksum cannot be verified or a
log entry is determined to be invalid by examining its contents.EnvironmentFailureException - if an unexpected, internal or
environment-wide failure occurs.java.io.IOExceptionpublic long skip(long bytesToSkip)
throws java.io.IOException
This method reads the underlying InputStream in order to
skip the required number of bytes and verifies the contents of the
stream. A temporary buffer is allocated lazily for reading.
skip in class java.io.InputStreamLogVerificationException - if a checksum cannot be verified or a
log entry is determined to be invalid by examining its contents.EnvironmentFailureException - if an unexpected, internal or
environment-wide failure occurs.java.io.IOExceptionpublic int available()
throws java.io.IOException
This method simply performs in.available().
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
This method simply performs in.close().
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionCopyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.