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 call the close()
method of the LogVerificationInputStream
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(EnvironmentImpl envImpl,
java.io.InputStream in,
java.lang.String fileName,
long fileNum)
Internal constructor.
|
LogVerificationInputStream(Environment env,
java.io.InputStream in,
java.lang.String fileName)
Creates a verification input stream.
|
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
hexidecimal format.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.LogVerificationInputStream(EnvironmentImpl envImpl, java.io.InputStream in, java.lang.String fileName, long fileNum)
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.InputStream
LogVerificationException
- 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.IOException
public 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.InputStream
LogVerificationException
- 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.IOException
public 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.InputStream
LogVerificationException
- 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.IOException
public 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.InputStream
LogVerificationException
- 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.IOException
public int available() throws java.io.IOException
This method simply performs in.available()
.
available
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
This method closes the underlying InputStream
and verifies
that the stream ends with a complete log entry.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
LogVerificationException
- if the stream does not end with a
complete log entry.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.java.io.IOException
Copyright (c) 2004-2012 Oracle. All rights reserved.