public class DatabaseDumpChecker
extends java.lang.Object
cfg/p2j.cfg.xml
instead of command-line arguments;Modifier and Type | Field and Description |
---|---|
private static int |
debugLevel
The level of verbosity.
|
private static byte[] |
map
The byte map.
|
private static int |
READ_BUFFER_MAX_SIZE
The read buffer size of 1 MiB.
|
private static java.nio.charset.Charset |
sourceCS
The character decoder for read operation.
|
private static char |
TARGET_REPLACEMENT_CHAR
Fixed replacement character for encoding test.
|
private static java.nio.charset.Charset |
targetCS
The character encoder for simulated write operation.
|
private static long |
totalBytes
Counter for the bytes read.
|
private static long |
totalErrors
Counter for the errors encountered.
|
Constructor and Description |
---|
DatabaseDumpChecker() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
incrementError(java.util.Map<java.lang.Byte,java.util.concurrent.atomic.AtomicLong> errors,
byte errByte)
Increments the occurrences of an error for a specific byte.
|
private static boolean |
incrementError(java.util.Map<java.lang.Character,java.util.concurrent.atomic.AtomicLong> errors,
char errChar)
Increments the occurrences of an error for a specific character.
|
static void |
main(java.lang.String[] args)
The entry point of the application.
|
private static void |
print(int level,
java.lang.String format,
java.lang.Object... args)
Prints a filtered line to standard output stream.
|
private static void |
process(java.lang.String fileName)
Process a file.
|
private static java.lang.String |
toHexString(byte[] utfBytes)
Converts a byte array into its string format.
|
private static final int READ_BUFFER_MAX_SIZE
private static final char TARGET_REPLACEMENT_CHAR
private static long totalBytes
private static long totalErrors
private static java.nio.charset.Charset sourceCS
private static java.nio.charset.Charset targetCS
private static final byte[] map
private static int debugLevel
public static void main(java.lang.String[] args)
process()
method to analyze them individually and print a summary
at the end.args
- Standard parameter passing for a Java application.private static void process(java.lang.String fileName)
The file is read in batches of 1MiB.
The batch of bytes is converted to characters. If error is encountered it is logged and the fix is
attempted using the replacement byte. The process continues at the next unprocessed byte. When the whole
batch was processed and errors fixed, the buffer is rewound and a new decoding is attempted with fully
fixed buffer. If there are still errors they are reported as non-recoverable errors.
If no errors were detected or all of them were recovered by mapping bytes the write test is performed.
Like for reading, the character buffer is converted to bytes using the target Charset. In the event of
an unmappable character is is logged and replaced with TARGET_REPLACEMENT_CHAR. The process continues
with the rest of the character buffer until it was processed entirely. At this moment the buffer is
rewound and a full-size encoding is attempted with updated characters. If process fails it is reported
as a non-recoverable write error.
At this moment the next batch from the input stream is read and the process continues until the end of
the file.
When the entire file was processed, the file summary is reported.
fileName
- The name of the file to be processed (full path).private static java.lang.String toHexString(byte[] utfBytes)
Arrays.toString()
is that
this method will print bytes with 2 digits hexadecimal instead of signed decimal.utfBytes
- The bytes to be processed.private static boolean incrementError(java.util.Map<java.lang.Character,java.util.concurrent.atomic.AtomicLong> errors, char errChar)
errors
- The map to be updated.errChar
- The faulty character.true
if this is the first occurrence of the errByte
.private static boolean incrementError(java.util.Map<java.lang.Byte,java.util.concurrent.atomic.AtomicLong> errors, byte errByte)
errors
- The map to be updated.errByte
- The faulty byte.true
if this is the first occurrence of the errByte
.private static void print(int level, java.lang.String format, java.lang.Object... args)
level
- The level of the event.format
- The format to be applied.args
- The arguments which are used to replace the placeholders in the format.