@@ -68,7 +68,7 @@ public synchronized Iterable<ByteBuffer> split(ByteBuffer inputByteBuffer) {
6868
6969 // If current buffer is not empty, fill the buffer first.
7070 if (currentBuffer .position () != 0 ) {
71- fillBuffer (inputByteBuffer );
71+ fillCurrentBuffer (inputByteBuffer );
7272
7373 if (isCurrentBufferFull ()) {
7474 addCurrentBufferToIterable (byteBuffers , chunkSize );
@@ -77,7 +77,7 @@ public synchronized Iterable<ByteBuffer> split(ByteBuffer inputByteBuffer) {
7777
7878 // If the input buffer is not empty, split the input buffer
7979 if (inputByteBuffer .hasRemaining ()) {
80- splitInputBuffer (inputByteBuffer , byteBuffers );
80+ splitRemainingInputByteBuffer (inputByteBuffer , byteBuffers );
8181 }
8282
8383 // If this is the last chunk, add data buffered to the iterable
@@ -92,18 +92,18 @@ private boolean isCurrentBufferFull() {
9292 return currentBuffer .position () == chunkSize ;
9393 }
9494
95- private void splitInputBuffer (ByteBuffer buffer , List <ByteBuffer > byteBuffers ) {
96- while (buffer .hasRemaining ()) {
97- ByteBuffer chunkByteBuffer = buffer .asReadOnlyBuffer ();
98- if (buffer .remaining () < chunkSize ) {
99- currentBuffer .put (buffer );
95+ private void splitRemainingInputByteBuffer (ByteBuffer inputByteBuffer , List <ByteBuffer > byteBuffers ) {
96+ while (inputByteBuffer .hasRemaining ()) {
97+ ByteBuffer inputByteBufferCopy = inputByteBuffer .asReadOnlyBuffer ();
98+ if (inputByteBuffer .remaining () < chunkSize ) {
99+ currentBuffer .put (inputByteBuffer );
100100 break ;
101101 }
102102
103- int newLimit = chunkByteBuffer .position () + chunkSize ;
104- chunkByteBuffer .limit (newLimit );
105- buffer .position (newLimit );
106- byteBuffers .add (chunkByteBuffer );
103+ int newLimit = inputByteBufferCopy .position () + chunkSize ;
104+ inputByteBufferCopy .limit (newLimit );
105+ inputByteBuffer .position (newLimit );
106+ byteBuffers .add (inputByteBufferCopy );
107107 transferredBytes .addAndGet (chunkSize );
108108 }
109109 }
@@ -123,7 +123,7 @@ private void addCurrentBufferToIterable(List<ByteBuffer> byteBuffers, int capaci
123123 currentBuffer .clear ();
124124 }
125125
126- private void fillBuffer (ByteBuffer inputByteBuffer ) {
126+ private void fillCurrentBuffer (ByteBuffer inputByteBuffer ) {
127127 while (currentBuffer .position () < chunkSize ) {
128128 if (!inputByteBuffer .hasRemaining ()) {
129129 break ;
0 commit comments