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
Modifier and TypeFieldDescriptionprivate final ReadableByteChannel
The underlyingReadableByteChannel
to use for readingprivate final long
The expected total size in bytes to be readprivate final ProgressRBCWrapperListener
TheProgressRBCWrapperListener
that is keeping track of progressprivate long
The amount of bytes read so far -
Constructor Summary
ConstructorDescriptionProgressReadableByteChannelWrapper
(ReadableByteChannel byteChannel, ProgressRBCWrapperListener listener, long expectedSize) Wraps the givenReadableByteChannel
so we can send progress updates to the givenProgressRBCWrapperListener
, which is keeping track of progress -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the underlyingbyteChannel
boolean
isOpen()
int
read
(ByteBuffer bb) Reads bytes from the underlyingbyteChannel
into the givenByteBuffer
and will send a progress update to thelistener
that is keeping track of progress
-
Field Details
-
byteChannel
The underlyingReadableByteChannel
to use for reading -
listener
TheProgressRBCWrapperListener
that 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 givenReadableByteChannel
so we can send progress updates to the givenProgressRBCWrapperListener
, which is keeping track of progress- Parameters:
byteChannel
- The underlyingReadableByteChannel
to be wrappedlistener
- TheProgressRBCWrapperListener
which will track progressexpectedSize
- The expected total size in bytes to be read
-
-
Method Details
-
close
Closes the underlyingbyteChannel
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If anything goes wrong in closing the byte channel
-
isOpen
public boolean isOpen()- Specified by:
isOpen
in interfaceChannel
- Returns:
- Whether the underlying
byteChannel
is open or not
-
read
Reads bytes from the underlyingbyteChannel
into the givenByteBuffer
and will send a progress update to thelistener
that is keeping track of progress- Specified by:
read
in interfaceReadableByteChannel
- Parameters:
bb
- TheByteBuffer
to 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
-