Package org.apache.hadoop.fs
Class FSOutputSummer
java.lang.Object
java.io.OutputStream
org.apache.hadoop.fs.FSOutputSummer
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,StreamCapabilities
@LimitedPrivate("HDFS")
@Unstable
public abstract class FSOutputSummer
extends OutputStream
implements StreamCapabilities
This is a generic output stream for generating checksums for
data before it is written to the underlying stream
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.fs.StreamCapabilities
StreamCapabilities.StreamCapability -
Field Summary
Fields inherited from interface org.apache.hadoop.fs.StreamCapabilities
ABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO, VECTOREDIO_BUFFERS_SLICED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidCheck if the implementing OutputStream is closed and should no longer accept writes.static byte[]convertToByteStream(Checksum sum, int checksumSize) Converts a checksum integer value to a byte streamprotected org.apache.hadoop.tracing.TraceScopevoidflush()Checksums all complete data chunks and flushes them to the underlying stream.protected voidprotected intflushBuffer(boolean keep, boolean flushPartial) protected intReturn the number of valid bytes currently in the buffer.protected intprotected DataChecksumbooleanhasCapability(String capability) Query the stream for a specific capability.protected voidprotected voidsetChecksumBufSize(int size) Resets existing buffer with a new one of the specified size.voidwrite(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffand generate a checksum for each data chunk.voidwrite(int b) Write one byteprotected abstract voidwriteChunk(byte[] b, int bOffset, int bLen, byte[] checksum, int checksumOffset, int checksumLen) Methods inherited from class java.io.OutputStream
close, nullOutputStream, write
-
Constructor Details
-
FSOutputSummer
-
-
Method Details
-
writeChunk
protected abstract void writeChunk(byte[] b, int bOffset, int bLen, byte[] checksum, int checksumOffset, int checksumLen) throws IOException - Throws:
IOException
-
checkClosed
Check if the implementing OutputStream is closed and should no longer accept writes. Implementations should do nothing if this stream is not closed, and should throw anIOExceptionif it is closed.- Throws:
IOException- if this stream is already closed.
-
write
Write one byte- Specified by:
writein classOutputStream- Throws:
IOException
-
write
Writeslenbytes from the specified byte array starting at offsetoffand generate a checksum for each data chunk.This method stores bytes from the given array into this stream's buffer before it gets checksumed. The buffer gets checksumed and flushed to the underlying output stream when all data in a checksum chunk are in the buffer. If the buffer is empty and requested length is at least as large as the size of next checksum chunk size, this method will checksum and write the chunk directly to the underlying output stream. Thus it avoids unnecessary data copy.
- Overrides:
writein classOutputStream- Parameters:
b- the data.off- the start offset in the data.len- the number of bytes to write.- Throws:
IOException- if an I/O error occurs.
-
flushBuffer
- Throws:
IOException
-
flushBuffer
- Throws:
IOException
-
flush
Checksums all complete data chunks and flushes them to the underlying stream. If there is a trailing partial chunk, it is not flushed and is maintained in the buffer.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
getBufferedDataSize
protected int getBufferedDataSize()Return the number of valid bytes currently in the buffer.- Returns:
- buffer data size.
-
getChecksumSize
protected int getChecksumSize()- Returns:
- the size for a checksum.
-
getDataChecksum
-
createWriteTraceScope
protected org.apache.hadoop.tracing.TraceScope createWriteTraceScope() -
convertToByteStream
Converts a checksum integer value to a byte stream- Parameters:
sum- check sum.checksumSize- check sum size.- Returns:
- byte stream.
-
setChecksumBufSize
protected void setChecksumBufSize(int size) Resets existing buffer with a new one of the specified size.- Parameters:
size- size.
-
resetChecksumBufSize
protected void resetChecksumBufSize() -
hasCapability
Description copied from interface:StreamCapabilitiesQuery the stream for a specific capability.- Specified by:
hasCapabilityin interfaceStreamCapabilities- Parameters:
capability- string to query the stream support for.- Returns:
- True if the stream supports capability.
-