27import java.nio.ByteBuffer;
28import java.nio.charset.Charset;
29import java.nio.file.Path;
30import java.nio.file.Paths;
31import java.util.ArrayList;
32import java.util.Arrays;
35import org.jau.fs.FMode;
36import org.jau.fs.FileStats;
37import org.jau.fs.FileUtil;
38import org.jau.fs.TraverseOptions;
39import org.jau.io.Buffers;
40import org.jau.io.ByteInStream;
41import org.jau.io.ByteInStreamUtil;
42import org.jau.io.ByteInStream_Feed;
43import org.jau.io.ByteInStream_File;
44import org.jau.io.ByteInStream_URL;
45import org.jau.io.ByteOutStream_File;
46import org.jau.io.PrintUtil;
47import org.jau.io.UriTk;
48import org.junit.AfterClass;
49import org.junit.Assert;
50import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
54import jau.pkg.PlatformRuntime;
55import jau.test.junit.util.JunitTracer;
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59 static final boolean DEBUG =
false;
61 static final String payload_version =
"0";
62 static final String payload_version_parent =
"0";
64 static final int IDX_11kiB = 0;
65 static final int IDX_65MiB = 1;
66 static List<String> fname_payload_lst =
new ArrayList<String>();
67 static List<String> fname_payload_copy_lst =
new ArrayList<String>();
68 static List<Long> fname_payload_size_lst =
new ArrayList<Long>();
70 static boolean file_exists(
final String name) {
75 static long file_size(
final String name) {
80 static boolean remove_file(
final String name) {
85 PrintUtil.
println(System.err,
"Remove.1: Failed deletion of existing file "+name);
91 }
catch (
final Exception ex) {
92 PrintUtil.
println(System.err,
"Remove.2: Failed deletion of existing file "+name+
": "+ex.getMessage());
98 static boolean add_test_file(
final String name,
final long size_limit) {
99 Assert.assertTrue( remove_file(name) );
100 Assert.assertTrue( remove_file(name+
".enc") );
101 Assert.assertTrue( remove_file(name+
".enc.dec") );
104 final String one_line =
"Hello World, this is a test and I like it. Exactly 100 characters long. 0123456780 abcdefghjklmnop..";
105 final Charset charset = Charset.forName(
"ASCII");
106 final byte[] one_line_bytes = one_line.getBytes(charset);
108 Assert.assertFalse( file_exists(name) );
110 Assert.assertTrue( out.good() );
111 Assert.assertTrue( out.is_open() );
113 final int line_len = one_line_bytes.length;
114 for(size=0; size < size_limit; size+=line_len) {
115 if( line_len != out.write( one_line_bytes, 0, line_len ) ) {
116 PrintUtil.
fprintf_td(System.err,
"Write %d bytes to test file failed: %s", line_len, out.toString());
120 if( 1 != out.write( one_line_bytes, 0, 1 ) ) {
121 PrintUtil.
fprintf_td(System.err,
"Write %d bytes to test file failed: %s", 1, out.toString());
128 fname_payload_lst.add(name);
129 fname_payload_copy_lst.add(name+
".copy");
130 fname_payload_size_lst.add( Long.valueOf(size) );
136 Assert.assertTrue( add_test_file(
"test_cipher_01_11kiB.bin", 1024*11) );
137 Assert.assertTrue( add_test_file(
"test_cipher_02_65MiB.bin", 1024*1024*65) );
140 static boolean system(
final String[] command) {
143 proc = Runtime.getRuntime().exec(command);
147 catch(
final Exception ex)
152 ex.printStackTrace();
157 static final String mini_httpd_exe() {
158 final String os_name = System.getProperty(
"os.name");
159 if(
"FreeBSD".equals(os_name) ) {
160 return "/usr/local/sbin/mini_httpd";
162 return "/usr/sbin/mini_httpd";
169 Assert.assertTrue( system(
new String[]{
"killall",
"mini_httpd"}) );
173 static void httpd_start() {
175 Assert.assertTrue( system(
new String[]{
"killall",
"mini_httpd"}) );
176 final Path path = Paths.get(
"");
177 final String directoryName = path.toAbsolutePath().toString();
178 final String[] cmd =
new String[]{mini_httpd_exe(),
"-p",
"8080",
"-l", directoryName+
"/mini_httpd.log"};
179 PrintUtil.fprintf_td(System.err,
"%s%n", Arrays.toString(cmd));
180 Assert.assertTrue( system(cmd) );
184 final static String url_input_root =
"http://localhost:8080/";
187 static boolean transfer_std(
final ByteInStream input,
final String output_fname,
final int buffer_size) {
188 final long _t0 = org.jau.sys.Clock.currentTimeMillis();
189 PrintUtil.fprintf_td(System.err,
"Transfer Start: %s%n", input);
190 remove_file(output_fname);
192 if( file_exists( output_fname ) ) {
195 final long[] out_bytes_payload = { 0 };
196 try ( ByteOutStream_File out =
new ByteOutStream_File(output_fname, FMode.def_file) ) {
198 Assert.assertTrue( out.good() );
200 final ByteInStreamUtil.StreamConsumer1 consumer = (
final byte[] data,
final int data_len,
final boolean is_final) -> {
201 if( !is_final && ( !input.has_content_size() || out_bytes_payload[0] + data_len < input.content_size() ) ) {
202 final int written = out.write( data, 0, data_len );
203 out_bytes_payload[0] += written;
204 return data_len == written;
206 final int written = out.write( data, 0, data_len );
207 out_bytes_payload[0] += written;
211 final byte[] io_buffer =
new byte[buffer_size];
212 final long in_bytes_total = ByteInStreamUtil.read_stream(input, io_buffer, consumer);
216 if ( 0==in_bytes_total || input.fail() ) {
217 PrintUtil.fprintf_td(System.err,
"ByteStream copy failed: Input file read failed in %s, out %s%n", input, out);
221 PrintUtil.fprintf_td(System.err,
"ByteStream copy failed: Output file write failed in %s, out %s%n", input, out);
226 final long _td = org.jau.sys.Clock.currentTimeMillis() - _t0;
227 ByteInStreamUtil.print_stats(
"Transfer "+output_fname, out_bytes_payload[0], _td);
228 PrintUtil.fprintf_td(System.err,
"Transfer End: %s%n", input.toString());
233 static boolean transfer_nio(
final ByteInStream input,
final String output_fname,
final int buffer_size) {
234 final long _t0 = org.jau.sys.Clock.currentTimeMillis();
235 PrintUtil.fprintf_td(System.err,
"Transfer Start: %s%n", input);
236 remove_file(output_fname);
238 if( file_exists( output_fname ) ) {
241 final long[] out_bytes_payload = { 0 };
242 try ( ByteOutStream_File out =
new ByteOutStream_File(output_fname, FMode.def_file) ) {
243 Assert.assertTrue( out.good() );
245 final ByteInStreamUtil.StreamConsumer2 consumer = (
final ByteBuffer data,
final boolean is_final) -> {
246 final int data_len = data.remaining();
247 if( !is_final && ( !input.has_content_size() || out_bytes_payload[0] + data_len < input.content_size() ) ) {
248 final int written = out.write(data);
250 out_bytes_payload[0] += written;
251 return written == data_len;
253 final int written = out.write(data);
255 out_bytes_payload[0] += written;
259 final ByteBuffer io_buffer = Buffers.newDirectByteBuffer(buffer_size);
260 final long in_bytes_total = ByteInStreamUtil.read_stream(input, io_buffer, consumer);
264 if ( 0==in_bytes_total || input.fail() ) {
265 PrintUtil.fprintf_td(System.err,
"ByteStream copy failed: Input file read failed in %s, out %s%n", input, out);
269 PrintUtil.fprintf_td(System.err,
"ByteStream copy failed: Output file write failed in %s, out %s%n", input, out);
274 final long _td = org.jau.sys.Clock.currentTimeMillis() - _t0;
275 ByteInStreamUtil.print_stats(
"Transfer "+output_fname, out_bytes_payload[0], _td);
276 PrintUtil.fprintf_td(System.err,
"Transfer End: %s%n", input.toString());
281 @Test(timeout = 10000)
282 public final
void test00a_protocols_error() {
289 PrintUtil.
fprintf_td(System.err,
"test00_protocols: Supported protocols: %d: %s%n", protos.size(), protos);
290 if( http_support_expected ) {
291 Assert.assertTrue( 0 < protos.size() );
293 Assert.assertTrue( 0 == protos.size() );
296 final int file_idx = IDX_11kiB;
298 final String url =
"not_exiting_file.txt";
306 Assert.assertNull(in);
310 final String url =
"file://not_exiting_file_uri.txt";
318 Assert.assertNull(in);
322 final String url =
"lala://localhost:8080/" + fname_payload_lst.get(file_idx);
330 Assert.assertNull(in);
334 final String url = url_input_root +
"not_exiting_http_uri.txt";
339 if( http_support_expected ) {
340 Assert.assertNotNull(in);
341 try { Thread.sleep(100); }
catch (
final Throwable t) {}
343 Assert.assertFalse( in.good() );
344 Assert.assertTrue( in.fail() );
345 Assert.assertEquals( 0, in.content_size() );
347 Assert.assertNull(in);
353 @Test(timeout = 10000)
354 public final
void test00b_protocols_ok() {
359 final int file_idx = IDX_11kiB;
361 final String url = fname_payload_lst.get(file_idx);
369 Assert.assertNotEquals(
null, in );
370 Assert.assertFalse( in.fail() );
372 final boolean res = transfer_nio(in, fname_payload_copy_lst.get(file_idx), 4096);
373 Assert.assertTrue( res );
375 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
376 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
377 Assert.assertEquals( in.content_size(), copy_size );
378 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
379 Assert.assertTrue(
FileUtil.
compare(in.id(), fname_payload_copy_lst.get(file_idx),
true ) );
383 final String url =
"file://" + fname_payload_lst.get(file_idx);
391 Assert.assertNotNull( in );
392 Assert.assertFalse( in.fail() );
394 final boolean res = transfer_nio(in, fname_payload_copy_lst.get(file_idx), 4096);
395 Assert.assertTrue( res );
397 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
398 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
399 Assert.assertEquals( in.content_size(), copy_size );
400 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
401 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
405 final String url = url_input_root + fname_payload_lst.get(file_idx);
413 if( http_support_expected ) {
414 Assert.assertNotNull( in );
415 Assert.assertFalse( in.fail() );
417 final boolean res = transfer_nio(in, fname_payload_copy_lst.get(file_idx), 4096);
418 Assert.assertTrue( res );
420 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
421 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
422 Assert.assertEquals( in.content_size(), copy_size );
423 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
424 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
426 Assert.assertNull( in );
432 @Test(timeout = 10000)
433 public
void test01_copy_file_ok_11kiB() {
435 final int file_idx = IDX_11kiB;
437 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 4096);
438 Assert.assertTrue( res );
440 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
441 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
442 Assert.assertEquals( data_stream.content_size(), copy_size );
443 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
444 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
448 @Test(timeout = 10000)
449 public
void test02_copy_file_ok_65MiB_nio_buff4k() {
451 final int file_idx = IDX_65MiB;
453 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 4096);
454 Assert.assertTrue( res );
456 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
457 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
458 Assert.assertEquals( data_stream.content_size(), copy_size );
459 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
460 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
464 @Test(timeout = 10000)
465 public
void test03_copy_file_ok_65MiB_std_buff4k() {
467 final int file_idx = IDX_65MiB;
469 final boolean res = transfer_std(data_stream, fname_payload_copy_lst.get(file_idx), 4096);
470 Assert.assertTrue( res );
472 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
473 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
474 Assert.assertEquals( data_stream.content_size(), copy_size );
475 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
476 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
480 @Test(timeout = 10000)
481 public
void test04_copy_file_ok_65MiB_nio_buff32k() {
483 final int file_idx = IDX_65MiB;
485 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 32768);
486 Assert.assertTrue( res );
488 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
489 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
490 Assert.assertEquals( data_stream.content_size(), copy_size );
491 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
492 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
496 @Test(timeout = 10000)
497 public
void test05_copy_file_ok_65MiB_std_buff32k() {
499 final int file_idx = IDX_65MiB;
501 final boolean res = transfer_std(data_stream, fname_payload_copy_lst.get(file_idx), 32768);
502 Assert.assertTrue( res );
504 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
505 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
506 Assert.assertEquals( data_stream.content_size(), copy_size );
507 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
508 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
512 @Test(timeout = 10000)
513 public
void test11_copy_http_ok_nio_buff32k() {
521 final int file_idx = IDX_11kiB;
523 final String uri_original = url_input_root + fname_payload_lst.get(file_idx);
526 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 32768);
527 Assert.assertTrue( res );
529 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
530 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
531 Assert.assertEquals( data_stream.content_size(), copy_size );
532 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
533 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
537 final int file_idx = IDX_65MiB;
539 final String uri_original = url_input_root + fname_payload_lst.get(file_idx);
542 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 32768);
543 Assert.assertTrue( res );
545 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
546 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
547 Assert.assertEquals( data_stream.content_size(), copy_size );
548 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
549 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
554 @Test(timeout = 10000)
555 public
void test12_copy_http_404() {
563 final int file_idx = IDX_11kiB;
565 final String uri_original = url_input_root +
"doesnt_exists.txt";
568 final boolean res = transfer_nio(data_stream, fname_payload_copy_lst.get(file_idx), 4096);
569 Assert.assertFalse( res );
571 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
572 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
573 Assert.assertTrue( data_stream.fail() );
574 Assert.assertFalse( data_stream.has_content_size() );
575 Assert.assertEquals( data_stream.content_size(), 0 );
576 Assert.assertEquals( 0, copy_size );
581 static Thread executeOffThread(
final Runnable runobj,
final String threadName,
final boolean detach) {
582 final Thread t =
new Thread( runobj, threadName );
583 t.setDaemon( detach );
589 static void feed_source_00(
final ByteInStream_Feed data_feed,
final int feed_size) {
591 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
592 final byte buffer[] =
new byte[feed_size];
593 while( data_stream.good() ) {
594 final int count = data_stream.read(buffer, 0, buffer.length);
597 if( data_feed.write(buffer, 0, count) ) {
598 try { Thread.sleep(16); }
catch (
final Throwable t) {}
605 data_feed.set_eof( data_feed.fail() ? -1 : 1 );
610 static void feed_source_01(
final ByteInStream_Feed data_feed,
final int feed_size) {
612 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
613 final long file_size = data_stream.content_size();
614 data_feed.set_content_size( file_size );
615 final byte buffer[] =
new byte[feed_size];
616 while( data_stream.good() && xfer_total < file_size ) {
617 final int count = data_stream.read(buffer, 0, buffer.length);
620 if( data_feed.write(buffer, 0, count) ) {
621 try { Thread.sleep(16); }
catch (
final Throwable t) {}
628 data_feed.set_eof( !data_feed.fail() && xfer_total == file_size ? 1 : -1 );
633 static void feed_source_10_nio(
final ByteInStream_Feed data_feed,
final int feed_size) {
635 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
636 final long file_size = data_stream.content_size();
637 data_feed.set_content_size( file_size );
638 final ByteBuffer buffer = Buffers.newDirectByteBuffer(feed_size);
639 while( data_stream.good() && xfer_total < file_size ) {
640 final int count = data_stream.read(buffer);
643 if( !data_feed.write(buffer) ) {
648 data_feed.set_eof( !data_feed.fail() && xfer_total == file_size ? 1 : -1 );
653 static void feed_source_10_std(
final ByteInStream_Feed data_feed,
final int feed_size) {
655 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
656 final long file_size = data_stream.content_size();
657 data_feed.set_content_size( file_size );
658 final byte buffer[] =
new byte[feed_size];
659 while( data_stream.good() && xfer_total < file_size ) {
660 final int count = data_stream.read(buffer, 0, buffer.length);
663 if( !data_feed.write(buffer, 0, count) ) {
668 data_feed.set_eof( !data_feed.fail() && xfer_total == file_size ? 1 : -1 );
673 static void feed_source_20(
final ByteInStream_Feed data_feed,
final int feed_size) {
675 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
676 final byte buffer[] =
new byte[feed_size];
677 while( data_stream.good() ) {
678 final int count = data_stream.read(buffer, 0, buffer.length);
681 if( data_feed.write(buffer, 0, count) ) {
682 if( xfer_total >= 1024 ) {
683 data_feed.set_eof( -1 );
697 static void feed_source_21(
final ByteInStream_Feed data_feed,
final int feed_size) {
699 try(
final ByteInStream_File data_stream =
new ByteInStream_File(data_feed.id() ) ) {
700 final long file_size = data_stream.content_size();
701 data_feed.set_content_size( file_size );
702 final byte buffer[] =
new byte[feed_size];
703 while( data_stream.good() ) {
704 final int count = data_stream.read(buffer, 0, buffer.length);
707 if( data_feed.write(buffer, 0, count) ) {
708 if( xfer_total >= file_size/4 ) {
709 data_feed.set_eof( -1 );
722 @Test(timeout = 10000)
723 public
void test20_copy_fed_ok_buff4k_feed1k() {
725 final int buffer_size = 4096;
726 final int feed_size = 1024;
728 final int file_idx = IDX_11kiB;
732 final Thread feeder_thread = executeOffThread( () -> { feed_source_10_nio(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_10",
false );
734 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
736 feeder_thread.join(1000);
737 }
catch (
final InterruptedException e) { }
738 Assert.assertTrue( res );
740 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
741 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
742 Assert.assertEquals( data_feed.content_size(), copy_size );
743 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
744 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
749 final Thread feeder_thread = executeOffThread( () -> { feed_source_01(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_01",
false );
751 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
753 feeder_thread.join(1000);
754 }
catch (
final InterruptedException e) { }
755 Assert.assertTrue( res );
757 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
758 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
759 Assert.assertEquals( data_feed.content_size(), copy_size );
760 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
761 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
766 final Thread feeder_thread = executeOffThread( () -> { feed_source_00(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_00",
false );
768 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
770 feeder_thread.join(1000);
771 }
catch (
final InterruptedException e) { }
772 Assert.assertTrue( res );
774 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
775 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
776 Assert.assertEquals( data_feed.content_size(), 0 );
777 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
778 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
782 final int file_idx = IDX_65MiB;
786 final Thread feeder_thread = executeOffThread( () -> { feed_source_10_nio(data_feed, feed_size); },
"test21_copy_fed_ok2::feed_source_10",
false );
788 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
790 feeder_thread.join(1000);
791 }
catch (
final InterruptedException e) { }
792 Assert.assertTrue( res );
794 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
795 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
796 Assert.assertEquals( data_feed.content_size(), copy_size );
797 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
798 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
803 @Test(timeout = 10000)
804 public
void test21_copy_fed_ok_buff32k() {
806 final int buffer_size = 32768;
807 final int feed_size = 32768;
809 final int file_idx = IDX_11kiB;
813 final Thread feeder_thread = executeOffThread( () -> { feed_source_10_nio(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_10",
false );
815 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
817 feeder_thread.join(1000);
818 }
catch (
final InterruptedException e) { }
819 Assert.assertTrue( res );
821 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
822 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
823 Assert.assertEquals( data_feed.content_size(), copy_size );
824 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
825 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
830 final Thread feeder_thread = executeOffThread( () -> { feed_source_01(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_01",
false );
832 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
834 feeder_thread.join(1000);
835 }
catch (
final InterruptedException e) { }
836 Assert.assertTrue( res );
838 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
839 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
840 Assert.assertEquals( data_feed.content_size(), copy_size );
841 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
842 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
847 final Thread feeder_thread = executeOffThread( () -> { feed_source_00(data_feed, feed_size); },
"test21_copy_fed_ok::feed_source_00",
false );
849 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
851 feeder_thread.join(1000);
852 }
catch (
final InterruptedException e) { }
853 Assert.assertTrue( res );
855 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
856 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
857 Assert.assertEquals( data_feed.content_size(), 0 );
858 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
859 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
864 @Test(timeout = 10000)
865 public
void test22_copy_fed_ok_buff32k_nio() {
867 final int buffer_size = 32768;
868 final int feed_size = 32768;
870 final int file_idx = IDX_65MiB;
874 final Thread feeder_thread = executeOffThread( () -> { feed_source_10_nio(data_feed, feed_size); },
"test21_copy_fed_ok2::feed_source_10",
false );
876 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
878 feeder_thread.join(1000);
879 }
catch (
final InterruptedException e) { }
880 Assert.assertTrue( res );
882 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
883 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
884 Assert.assertEquals( data_feed.content_size(), copy_size );
885 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
886 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
891 @Test(timeout = 10000)
892 public
void test23_copy_fed_ok_buff32k_std() {
894 final int buffer_size = 32768;
895 final int feed_size = 32768;
897 final int file_idx = IDX_65MiB;
901 final Thread feeder_thread = executeOffThread( () -> { feed_source_10_std(data_feed, feed_size); },
"test23_copy_fed_ok2::feed_source_10",
false );
903 final boolean res = transfer_std(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
905 feeder_thread.join(1000);
906 }
catch (
final InterruptedException e) { }
907 Assert.assertTrue( res );
909 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
910 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
911 Assert.assertEquals( data_feed.content_size(), copy_size );
912 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), copy_size );
913 Assert.assertTrue(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
918 @Test(timeout = 10000)
919 public
void test24_copy_fed_irq() {
921 final int buffer_size = 4096;
922 final int feed_size = 1024;
924 final int file_idx = IDX_65MiB;
928 final Thread feeder_thread = executeOffThread( () -> { feed_source_20(data_feed, feed_size); },
"test22_copy_fed_irq::feed_source_20",
false );
930 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
932 feeder_thread.join(1000);
933 }
catch (
final InterruptedException e) { }
934 Assert.assertFalse( res );
936 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
937 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
938 Assert.assertFalse( data_feed.has_content_size() );
939 Assert.assertEquals( data_feed.content_size(), 0 );
940 Assert.assertTrue( fname_payload_size_lst.get(file_idx).longValue() > copy_size );
941 Assert.assertFalse(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
946 final Thread feeder_thread = executeOffThread( () -> { feed_source_21(data_feed, feed_size); },
"test22_copy_fed_irq::feed_source_21",
false );
948 final boolean res = transfer_nio(data_feed, fname_payload_copy_lst.get(file_idx), buffer_size);
950 feeder_thread.join(1000);
951 }
catch (
final InterruptedException e) { }
952 Assert.assertFalse( res );
954 Assert.assertTrue( file_exists( fname_payload_copy_lst.get(file_idx) ) );
955 final long copy_size = file_size(fname_payload_copy_lst.get(file_idx));
956 Assert.assertTrue( data_feed.has_content_size() );
957 Assert.assertEquals( fname_payload_size_lst.get(file_idx).longValue(), data_feed.content_size() );
958 Assert.assertTrue( data_feed.content_size() > copy_size );
959 Assert.assertFalse(
FileUtil.
compare(fname_payload_lst.get(file_idx), fname_payload_copy_lst.get(file_idx),
true ) );
964 public static void main(
final String args[]) {
static void main(final String args[])
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
static final FMode def_file
Default file protection bit: Safe default: POSIX S_IRUSR | S_IWUSR | S_IRGRP or read_usr | write_usr ...
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
boolean is_file()
Returns true if entity is a file, might be in combination with is_link().
boolean exists()
Returns true if entity does not exist, exclusive bit.
long size()
Returns the size in bytes of this element if is_file(), otherwise zero.
Native file types and functionality.
static boolean remove(final String path, final TraverseOptions topts)
Remove the given path.
static native boolean compare(final String source1, final String source2, final boolean verbose)
Compare the bytes of both files, denoted by source1 and source2.
Filesystem traverse options used to visit() path elements.
static final TraverseOptions none
Ringbuffer-Based byte input stream with an externally provisioned data feed.
File based byte input stream, including named file descriptor.
Ringbuffer-Based byte input stream with a URL connection provisioned data feed.
File based byte output stream, including named file descriptor.
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
static void println(final PrintStream out, final String msg)
Convenient PrintStream#println(String) invocation, prepending the elapsedTimeMillis() timestamp.
Limited URI toolkit to query handled protocols by the IO implementation.
static native boolean is_local_file_protocol(final String uri)
Returns true if the uri-scheme of given uri matches the local file protocol, i.e.
static native List< String > supported_protocols()
Returns a list of supported protocol supported by libcurl network protocols, queried at runtime.
static native boolean protocol_supported(final String uri)
Returns true if the uri-scheme of given uri matches a supported by libcurl network protocols otherwis...
This class represents an abstract byte input stream object.
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.