|
Berkeley DB Java Edition version 5.0.34 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
com.sleepycat.je.util.LogVerificationInputStream
public class LogVerificationInputStream
Verifies the checksums in an 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 Summary | |
---|---|
LogVerificationInputStream(Environment env,
InputStream in,
String fileName)
Creates a verification input stream. |
Method Summary | |
---|---|
int |
available()
|
void |
close()
|
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
|
long |
skip(long bytesToSkip)
|
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LogVerificationInputStream(Environment env, InputStream in, 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.Method Detail |
---|
public int read() throws IOException
This method reads the underlying InputStream
and verifies the
contents of the stream.
read
in class 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.
IOException
public int read(byte[] b) throws IOException
This method reads the underlying InputStream
and verifies the
contents of the stream.
read
in class 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.
IOException
public int read(byte[] b, int off, int len) throws IOException
This method reads the underlying InputStream
and verifies the
contents of the stream.
read
in class 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.
IOException
public long skip(long bytesToSkip) throws 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 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.
IOException
public int available() throws IOException
This method simply performs in.available()
.
available
in class InputStream
IOException
public void close() throws IOException
This method closes the underlying InputStream
and verifies
that the stream ends with a complete log entry.
close
in interface Closeable
close
in class InputStream
LogVerificationException
- if the stream does not end with a
complete log entry.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IOException
|
Berkeley DB Java Edition version 5.0.34 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |