Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed reading the data within the block #70

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ public void read(long offsetBytes, ByteBuffer buffer) {
final int blocksPerTransfer = mMaxTransferSize / mBlockSize;

int offsetBlocks = (int) (offsetBytes / mBlockSize);
int blockOffset = (int) (offsetBytes % mBlockSize);
int blocksLeft = (short) Math.ceil((float) buffer.remaining() / mBlockSize);

boolean isFirstBlock = true;
while (blocksLeft > 0) {
final short requestedBlocks = (short) Math.min(blocksPerTransfer, blocksLeft);
final int requestedSize = requestedBlocks * mBlockSize;
Expand All @@ -205,8 +207,10 @@ public void read(long offsetBytes, ByteBuffer buffer) {
final byte[] buf = mAbstractBulkDevice.read(mBlockSize);

if (blocksLeft-- > 0) {
final int subLength = Math.min(mBlockSize, buffer.remaining());
buffer.put(buf, 0, subLength);
final int subLength = Math.min(mBlockSize - (isFirstBlock ? blockOffset : 0), buffer.remaining());
buffer.put(buf, (isFirstBlock ? blockOffset : 0), subLength);

isFirstBlock = false;
}
}

Expand Down