diff --git a/bt-core/src/main/java/bt/data/file/FileSystemStorageUnit.java b/bt-core/src/main/java/bt/data/file/FileSystemStorageUnit.java index 312d7e7c44..7257a9acd9 100644 --- a/bt-core/src/main/java/bt/data/file/FileSystemStorageUnit.java +++ b/bt-core/src/main/java/bt/data/file/FileSystemStorageUnit.java @@ -88,7 +88,10 @@ public synchronized void readBlock(ByteBuffer buffer, long offset) { try { sbc.position(offset); - sbc.read(buffer); + int read = 1; + while (buffer.hasRemaining() && read > 0) { + read = sbc.read(buffer); + } } catch (IOException e) { throw new BtException("Failed to read bytes (offset: " + offset + @@ -115,9 +118,12 @@ public synchronized byte[] readBlock(long offset, int length) { try { sbc.position(offset); - byte[] block = new byte[length]; - sbc.read(ByteBuffer.wrap(block)); - return block; + ByteBuffer buf = ByteBuffer.allocate(length); + int read = 1; + while(buf.hasRemaining() && read > 0) { + read = sbc.read(buf); + } + return buf.array(); } catch (IOException e) { throw new BtException("Failed to read bytes (offset: " + offset + @@ -141,7 +147,10 @@ public synchronized void writeBlock(ByteBuffer buffer, long offset) { try { sbc.position(offset); - sbc.write(buffer); + int written = 1; + while (buffer.hasRemaining() && written > 0) { + written = sbc.write(buffer); + } } catch (IOException e) { throw new BtException("Failed to write bytes (offset: " + offset + @@ -165,7 +174,11 @@ public synchronized void writeBlock(byte[] block, long offset) { try { sbc.position(offset); - sbc.write(ByteBuffer.wrap(block)); + ByteBuffer buf = ByteBuffer.wrap(block); + int written = 1; + while (buf.hasRemaining() && written > 0) { + written = sbc.write(buf); + } } catch (IOException e) { throw new BtException("Failed to write bytes (offset: " + offset +