Skip to content

Commit

Permalink
Add available() method to the streaming wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
eze210 committed Dec 18, 2024
1 parent 8b485bf commit 021d81f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public AbstractInputStreamBuffer(InputStream stream, ByteBufferManager bufferMan
this.bufferManager = bufferManager;
}

@Override
public int available() throws IOException {
return stream.available();
}

/**
* Consumes the stream in order to obtain data that has not been read yet.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ protected int doRead(byte[] b, int off, int len) throws IOException {
}
}

@Override
public int available() throws IOException {
return localBuffer.remaining() + streamBuffer.available();
}

private int assureDataInLocalBuffer(int len) {
if (len <= localBuffer.remaining()) {
return toIntExact(len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.mule.runtime.core.internal.streaming.bytes;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
Expand Down Expand Up @@ -36,4 +37,6 @@ public interface InputStreamBuffer {
* Releases all the resources held by this buffer
*/
void close();

int available() throws IOException;
}

0 comments on commit 021d81f

Please sign in to comment.