26import java.nio.ByteBuffer;
60 boolean consume(
byte[] data,
int data_len,
boolean is_final);
78 boolean has_more = in.
good();
81 final int got = in.
read(buffer, 0, buffer.length);
86 if( !consumer.
consume(buffer, got, !has_more) ) {
89 }
catch (
final Throwable e) {
90 PrintUtil.
fprintf_td(System.err,
"org.jau.nio.read_stream: Caught exception: %s", e.getMessage());
95 consumer.
consume(buffer, 0,
true);
111 boolean consume(ByteBuffer data,
boolean is_final);
125 final ByteBuffer buffer,
129 boolean has_more = in.
good();
132 final int got = in.
read(buffer);
137 if( !consumer.
consume(buffer, !has_more) ) {
140 }
catch (
final Throwable e) {
141 PrintUtil.
fprintf_td(System.err,
"org.jau.nio.read_stream: Caught exception: %s", e.getMessage());
164 if( !org.jau.io.UriTk.is_local_file_protocol(path_or_uri) &&
165 org.jau.io.UriTk.protocol_supported(path_or_uri) )
168 if(
null != res && !res.
fail() ) {
173 if(
null != res && !res.
fail() ) {
195 public static void print_stats(
final String prefix,
final long out_bytes_total,
final long td_ms) {
198 if( out_bytes_total >= 100000000 ) {
200 PrintUtil.
fprintf_td(System.err,
"%s: Size %,d MB%n", prefix, Math.round(out_bytes_total/1000000.0));
201 }
else if( out_bytes_total >= 100000 ) {
202 PrintUtil.
fprintf_td(System.err,
"%s: Size %,d KB%n", prefix, Math.round(out_bytes_total/1000.0));
207 final long _rate_bps = Math.round( out_bytes_total / ( td_ms / 1000.0 ));
208 final long _rate_bitps = Math.round( ( out_bytes_total * 8.0 ) / ( td_ms / 1000.0 ) );
210 if( _rate_bitps >= 100000000 ) {
212 Math.round(_rate_bitps/1000000.0),
213 Math.round(_rate_bps/1000000.0));
214 }
else if( _rate_bitps >= 100000 ) {
216 Math.round(_rate_bitps/10000), Math.round(_rate_bps/10000));
219 _rate_bitps, _rate_bps);
File based byte input stream, including named file descriptor.
Ringbuffer-Based byte input stream with a URL connection provisioned data feed.
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
Stream consumer using a byte array.
boolean consume(byte[] data, int data_len, boolean is_final)
Stream consumer using a direct ByteBuffer.
boolean consume(ByteBuffer data, boolean is_final)
This class represents an abstract byte input stream object.
static ByteInStream to_ByteInStream(final String path_or_uri)
Parses the given path_or_uri, if it matches a supported protocol, see org.jau.io.UriTk#protocol_suppo...
static long read_stream(final ByteInStream in, final byte buffer[], final StreamConsumer1 consumer)
Synchronous byte array input stream reader using the given StreamConsumer1.
static void print_stats(final String prefix, final long out_bytes_total, final long td_ms)
static long read_stream(final ByteInStream in, final ByteBuffer buffer, final StreamConsumer2 consumer)
Synchronous direct ByteBuffer input stream reader using the given StreamConsumer2.
static ByteInStream to_ByteInStream(final String path_or_uri, final long timeoutMS)
Parses the given path_or_uri, if it matches a supported protocol, see org.jau.io.UriTk#protocol_suppo...
Abstract byte input stream object.
long content_size()
Returns the content_size if known.
boolean available(long n)
Return whether n bytes are available in the input stream, if has_content_size() or using an asynchron...
int read(byte out[], final int offset, final int length)
Read from the source.
boolean has_content_size()
Returns true if implementation is aware of content_size(), otherwise false.
boolean fail()
Checks if an error has occurred.
boolean good()
Checks if no error nor eof() has occurred i.e.