Class FSInputChecker
- All Implemented Interfaces:
Closeable,AutoCloseable,PositionedReadable,Seekable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected PathThe file name from which data is read fromstatic final org.slf4j.Logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFSInputChecker(Path file, int numOfRetries) ConstructorprotectedFSInputChecker(Path file, int numOfRetries, boolean verifyChecksum, Checksum sum, int chunkSize, int checksumSize) Constructor -
Method Summary
Modifier and TypeMethodDescriptionintstatic longchecksum2long(byte[] checksum) Deprecated.protected abstract longgetChunkPosition(long pos) Return position of beginning of chunk containing pos.longgetPos()Return the current offset from the start of the filefinal voidmark(int readlimit) final booleanprotected booleanReturn true if there is a need for checksum verification.intread()Read one checksum-verified byteintread(byte[] b, int off, int len) Read checksum verified bytes from this byte-input stream into the specified byte array, starting at the given offset.protected final intreadAndDiscard(int len) Like read(byte[], int, int), but does not provide a dest buffer, so the read data is discarded.protected abstract intreadChunk(long pos, byte[] buf, int offset, int len, byte[] checksum) Reads in checksum chunks intobufatoffsetand checksum intochecksum.protected static intreadFully(InputStream stm, byte[] buf, int offset, int len) A utility function that tries to read up tolenbytes fromstmfinal voidreset()voidseek(long pos) Seek to the given position in the stream.protected final voidSet the checksum related parameterslongskip(long n) Skips over and discardsnbytes of data from the input stream.Methods inherited from class org.apache.hadoop.fs.FSInputStream
read, readFully, readFully, seekToNewSource, toString, validatePositionedReadArgsMethods inherited from class java.io.InputStream
close, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.fs.PositionedReadable
maxReadSizeForVectorReads, minSeekForVectorReads, readVectored, readVectored
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
file
The file name from which data is read from -
CHECKSUM_SIZE
protected static final int CHECKSUM_SIZE- See Also:
-
-
Constructor Details
-
FSInputChecker
Constructor- Parameters:
file- The name of the file to be readnumOfRetries- Number of read retries when ChecksumError occurs
-
FSInputChecker
protected FSInputChecker(Path file, int numOfRetries, boolean verifyChecksum, Checksum sum, int chunkSize, int checksumSize) Constructor- Parameters:
file- The name of the file to be readnumOfRetries- Number of read retries when ChecksumError occurssum- the type of Checksum enginechunkSize- maximun chunk sizechecksumSize- the number byte of each checksumverifyChecksum- verify check sum.
-
-
Method Details
-
readChunk
protected abstract int readChunk(long pos, byte[] buf, int offset, int len, byte[] checksum) throws IOException Reads in checksum chunks intobufatoffsetand checksum intochecksum. Since checksums can be disabled, there are two cases implementors need to worry about: (a) needChecksum() will return false: - len can be any positive value - checksum will be null Implementors should simply pass through to the underlying data stream. or (b) needChecksum() will return true: - len >= maxChunkSize - checksum.length is a multiple of CHECKSUM_SIZE Implementors should read an integer number of data chunks into buf. The amount read should be bounded by len or by checksum.length / CHECKSUM_SIZE * maxChunkSize. Note that len may be a value that is not a multiple of maxChunkSize, in which case the implementation may return less than len. The method is used for implementing read, therefore, it should be optimized for sequential reading.- Parameters:
pos- chunkPosbuf- destination bufferoffset- offset in buf at which to store datalen- maximum number of bytes to readchecksum- the data buffer into which to write checksums- Returns:
- number of bytes read
- Throws:
IOException- raised on errors performing I/O.
-
getChunkPosition
protected abstract long getChunkPosition(long pos) Return position of beginning of chunk containing pos.- Parameters:
pos- a position in the file- Returns:
- the starting position of the chunk which contains the byte
-
needChecksum
protected boolean needChecksum()Return true if there is a need for checksum verification.- Returns:
- if there is a need for checksum verification true, not false.
-
read
Read one checksum-verified byte- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-
read
Read checksum verified bytes from this byte-input stream into the specified byte array, starting at the given offset.This method implements the general contract of the corresponding
method of thereadclass. As an additional convenience, it attempts to read as many bytes as possible by repeatedly invoking theInputStreamreadmethod of the underlying stream. This iteratedreadcontinues until one of the following conditions becomes true:- The specified number of bytes have been read,
- The
readmethod of the underlying stream returns-1, indicating end-of-file.
readon the underlying stream returns-1to indicate end-of-file then this method returns-1. Otherwise this method returns the number of bytes actually read.- Overrides:
readin classInputStream- Parameters:
b- destination buffer.off- offset at which to start storing bytes.len- maximum number of bytes to read.- Returns:
- the number of bytes read, or
-1if the end of the stream has been reached. - Throws:
IOException- if an I/O error occurs. ChecksumException if any checksum error occurs
-
readAndDiscard
Like read(byte[], int, int), but does not provide a dest buffer, so the read data is discarded.- Parameters:
len- maximum number of bytes to read.- Returns:
- the number of bytes read.
- Throws:
IOException- if an I/O error occurs.
-
checksum2long
Deprecated.Convert a checksum byte array to a long This is deprecated since 0.22 since it is no longer in use by this class.- Parameters:
checksum- check sum.- Returns:
- crc.
-
getPos
Description copied from class:FSInputStreamReturn the current offset from the start of the file- Specified by:
getPosin interfaceSeekable- Specified by:
getPosin classFSInputStream- Returns:
- offset from the start of the file.
- Throws:
IOException- raised on errors performing I/O.
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
skip
Skips over and discardsnbytes of data from the input stream.This method may skip more bytes than are remaining in the backing file. This produces no exception and the number of bytes skipped may include some number of bytes that were beyond the EOF of the backing file. Attempting to read from the stream after skipping past the end will result in -1 indicating the end of the file.
If
nis negative, no bytes are skipped.- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if an I/O error occurs. ChecksumException if the chunk to skip to is corrupted
-
seek
Seek to the given position in the stream. The next read() will be from that position.This method may seek past the end of the file. This produces no exception and an attempt to read from the stream will result in -1 indicating the end of the file.
- Specified by:
seekin interfaceSeekable- Specified by:
seekin classFSInputStream- Parameters:
pos- the position to seek to.- Throws:
IOException- if an I/O error occurs. ChecksumException if the chunk to seek to is corrupted
-
readFully
A utility function that tries to read up tolenbytes fromstm- Parameters:
stm- an input streambuf- destination bufferoffset- offset at which to store datalen- number of bytes to read- Returns:
- actual number of bytes read
- Throws:
IOException- if there is any IO error
-
set
Set the checksum related parameters- Parameters:
verifyChecksum- whether to verify checksumsum- which type of checksum to usemaxChunkSize- maximun chunk sizechecksumSize- checksum size
-
markSupported
public final boolean markSupported()- Overrides:
markSupportedin classInputStream
-
mark
public final void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-