From 714324572a9c758326a971d9bc238b459faab3e4 Mon Sep 17 00:00:00 2001 From: Allen Field Date: Tue, 18 Oct 2016 15:36:25 +0800 Subject: [PATCH 1/3] fix write operation --- .../java/com/peircean/glusterfs/GlusterFileChannel.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java b/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java index a03ba28..b156ff9 100644 --- a/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java +++ b/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java @@ -166,7 +166,7 @@ long readHelper(ByteBuffer[] byteBuffers, int offset, int length) throws IOExcep public int write(ByteBuffer byteBuffer) throws IOException { guardClosed(); byte[] buf = byteBuffer.array(); - int written = GLFS.glfs_write(fileptr, buf, buf.length, 0); + int written = GLFS.glfs_write(fileptr, buf, byteBuffer.limit(), 0); if (written < 0) { throw new IOException(UtilJNI.strerror()); } @@ -189,17 +189,16 @@ public long write(ByteBuffer[] byteBuffers, int offset, int length) throws IOExc } long totalWritten = 0L; - for (int i = offset; i < length + offset; i++) { int remaining = byteBuffers[i].remaining(); while (remaining > 0) { byte[] bytes = byteBuffers[i].array(); - int written = GLFS.glfs_write(fileptr, bytes, remaining, 0); + int written = GLFS.glfs_write(fileptr, bytes, remaining, byteBuffers[i].position()); if (written < 0) { throw new IOException(); } position += written; - byteBuffers[i].position(written); + byteBuffers[i].position(remaining + written); totalWritten += written; remaining = byteBuffers[i].remaining(); } From 007bfc5b844816b4b039342335a883dfa045e154 Mon Sep 17 00:00:00 2001 From: fubai Date: Sun, 12 Feb 2017 15:35:36 +0800 Subject: [PATCH 2/3] fix test --- .../test/java/com/peircean/glusterfs/GlusterFileChannelTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/glusterfs-java-filesystem/src/test/java/com/peircean/glusterfs/GlusterFileChannelTest.java b/glusterfs-java-filesystem/src/test/java/com/peircean/glusterfs/GlusterFileChannelTest.java index 1f06449..0a4dac6 100644 --- a/glusterfs-java-filesystem/src/test/java/com/peircean/glusterfs/GlusterFileChannelTest.java +++ b/glusterfs-java-filesystem/src/test/java/com/peircean/glusterfs/GlusterFileChannelTest.java @@ -568,6 +568,7 @@ public void testWrite1Arg() throws IOException { when(GLFS.glfs_write(fileptr, bytes, bufferLength, 0)).thenReturn(bufferLength); doReturn(bytes).when(mockBuffer).array(); + doReturn(bufferLength).when(mockBuffer).limit(); doReturn(null).when(mockBuffer).position(bufferLength); int written = channel.write(mockBuffer); From f3eb389dc8553116fbac86bb11ae09563f52612a Mon Sep 17 00:00:00 2001 From: fubai Date: Sun, 12 Feb 2017 15:59:32 +0800 Subject: [PATCH 3/3] fix write operation --- .../main/java/com/peircean/glusterfs/GlusterFileChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java b/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java index b156ff9..825e29d 100644 --- a/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java +++ b/glusterfs-java-filesystem/src/main/java/com/peircean/glusterfs/GlusterFileChannel.java @@ -198,7 +198,7 @@ public long write(ByteBuffer[] byteBuffers, int offset, int length) throws IOExc throw new IOException(); } position += written; - byteBuffers[i].position(remaining + written); + byteBuffers[i].position(byteBuffers[i].position() + written); totalWritten += written; remaining = byteBuffers[i].remaining(); }