Package com.github.tadukoo.util.download
Class ProgressReadableByteChannelWrapper
java.lang.Object
com.github.tadukoo.util.download.ProgressReadableByteChannelWrapper
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ReadableByteChannel
Progress Readable Byte Channel Wrapper is a wrapper around
ReadableByteChannel that will send
progress updates to a ProgressRBCWrapperListener, which is keeping track of progress.- Version:
- Beta v.0.5
- Author:
- Logan Ferree (Tadukoo)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ReadableByteChannelThe underlyingReadableByteChannelto use for readingprivate final longThe expected total size in bytes to be readprivate final ProgressRBCWrapperListenerTheProgressRBCWrapperListenerthat is keeping track of progressprivate longThe amount of bytes read so far -
Constructor Summary
ConstructorsConstructorDescriptionProgressReadableByteChannelWrapper(ReadableByteChannel byteChannel, ProgressRBCWrapperListener listener, long expectedSize) Wraps the givenReadableByteChannelso we can send progress updates to the givenProgressRBCWrapperListener, which is keeping track of progress -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlyingbyteChannelbooleanisOpen()intread(ByteBuffer bb) Reads bytes from the underlyingbyteChannelinto the givenByteBufferand will send a progress update to thelistenerthat is keeping track of progress
-
Field Details
-
byteChannel
The underlyingReadableByteChannelto use for reading -
listener
TheProgressRBCWrapperListenerthat is keeping track of progress -
expectedSize
private final long expectedSizeThe expected total size in bytes to be read -
readSoFar
private long readSoFarThe amount of bytes read so far
-
-
Constructor Details
-
ProgressReadableByteChannelWrapper
public ProgressReadableByteChannelWrapper(ReadableByteChannel byteChannel, ProgressRBCWrapperListener listener, long expectedSize) Wraps the givenReadableByteChannelso we can send progress updates to the givenProgressRBCWrapperListener, which is keeping track of progress- Parameters:
byteChannel- The underlyingReadableByteChannelto be wrappedlistener- TheProgressRBCWrapperListenerwhich will track progressexpectedSize- The expected total size in bytes to be read
-
-
Method Details
-
close
Closes the underlyingbyteChannel- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- If anything goes wrong in closing the byte channel
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceChannel- Returns:
- Whether the underlying
byteChannelis open or not
-
read
Reads bytes from the underlyingbyteChannelinto the givenByteBufferand will send a progress update to thelistenerthat is keeping track of progress- Specified by:
readin interfaceReadableByteChannel- Parameters:
bb- TheByteBufferto be read into- Returns:
- The number of bytes read, possibly 0 or -1 if we're at the end of stream
- Throws:
IOException- If anything goes wrong in reading bytes
-