28package com.jogamp.common.nio;
31import java.io.IOException;
32import java.io.RandomAccessFile;
33import java.nio.channels.FileChannel;
35import org.junit.Assert;
38import com.jogamp.common.os.Platform;
39import com.jogamp.junit.util.SingletonJunitCase;
41import org.junit.FixMethodOrder;
42import org.junit.runners.MethodSorters;
48@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51 static void testImpl(
final String srcFileName,
final long size,
53 final String dstFileName,
55 System.err.println(
"Test: source[CacheMode "+srcCacheMode+
", SliceShift "+srcSliceShift+
"]");
56 System.err.println(
" destin[CacheMode "+dstCacheMode+
", SliceShift "+dstSliceShift+
"]");
57 final Runtime runtime = Runtime.getRuntime();
58 final long[] usedMem0 = { 0 };
59 final long[] freeMem0 = { 0 };
60 final long[] usedMem1 = { 0 };
61 final long[] freeMem1 = { 0 };
66 final File srcFile =
new File(srcFileName);
68 srcFile.createNewFile();
69 srcFile.deleteOnExit();
71 final RandomAccessFile input;
73 final RandomAccessFile _input =
new RandomAccessFile(srcFile,
"rw");
74 _input.setLength(size);
76 input =
new RandomAccessFile(srcFile,
"r");
80 FileChannel.MapMode.READ_ONLY,
83 Assert.assertEquals(size, input.length());
84 Assert.assertEquals(size, mis.
length());
85 Assert.assertEquals(0, mis.
position());
86 Assert.assertEquals(size, mis.
remaining());
88 final File dstFile =
new File(dstFileName);
90 dstFile.createNewFile();
91 dstFile.deleteOnExit();
92 final RandomAccessFile output =
new RandomAccessFile(dstFile,
"rw");
95 public void setLength(
final long newSize)
throws IOException {
100 FileChannel.MapMode.READ_WRITE,
102 srcSliceShift, szOp);
103 Assert.assertEquals(0, output.length());
104 Assert.assertEquals(0, mos.
length());
105 Assert.assertEquals(0, mos.
position());
108 OutOfMemoryError oome =
null;
109 IOException ioe =
null;
114 Assert.assertEquals(size, input.length());
115 Assert.assertEquals(size, output.length());
116 Assert.assertEquals(size, mis.
length());
117 Assert.assertEquals(size, mos.
length());
118 Assert.assertEquals(size, mis.
position());
119 Assert.assertEquals(size, mos.
position());
123 }
catch (
final IOException e) {
124 if( e.getCause() instanceof OutOfMemoryError ) {
125 oome = (OutOfMemoryError) e.getCause();
129 }
catch (
final OutOfMemoryError m) {
144 }
catch (
final InterruptedException e) { }
146 System.err.println(
"Performance Stats: ");
147 System.err.printf(
"- File-Create %6d ms\n", t1-t0);
148 System.err.printf(
"- File-Copy %6d ms\n", t5-t1);
149 System.err.printf(
"- GC %6d ms\n", t6-t5);
150 System.err.printf(
"- Total %6d ms\n", t6-t0);
152 if(
null != ioe ||
null != oome ) {
154 System.err.printf(
"%s: OutOfMemoryError.2 %s%n", prefix, oome.getMessage());
155 oome.printStackTrace();
157 Assert.assertNull(ioe);
163 static final long halfMiB = 1L << 19;
165 static final long quaterGiB = 1L << 28;
167 static final long quaterPlusGiB = quaterGiB + halfMiB;
169 static final long halfGiB = 1L << 29;
171 static final long halfPlusGiB = halfGiB + halfMiB;
173 static final long oneGiB = 1L << 30;
175 static final long onePlusGiB = oneGiB + halfMiB;
177 static final long twoGiB = ( 2L << 30 );
179 static final long twoPlusGiB = twoGiB + halfMiB;
182 static final long lala = ( 1L << 27 );
185 public void test00() throws IOException {
199 public void test01() throws IOException {
213 public void test02() throws IOException {
216 size = quaterPlusGiB;
220 final int srcSliceShift = 27;
221 final int dstSliceShift = 27;
227 public void test11() throws IOException {
228 final int srcSliceShift = 26;
229 final int dstSliceShift = 25;
230 final long size = quaterPlusGiB;
236 public void test12() throws IOException {
237 final int srcSliceShift = 25;
238 final int dstSliceShift = 26;
239 final long size = quaterPlusGiB;
244 static boolean manualTest =
false;
246 public static void main(
final String args[])
throws IOException {
247 for(
int i=0; i<args.length; i++) {
248 if(args[i].equals(
"-manual")) {
253 org.junit.runner.JUnitCore.
main(tstname);
An OutputStream implementation based on an underlying FileChannel's memory mapped ByteBuffer.
final synchronized long remaining()
See MappedByteBufferInputStream#remaining().
final synchronized long length()
See MappedByteBufferInputStream#length().
final synchronized void close()
final synchronized long position()
See MappedByteBufferInputStream#position().
final synchronized void write(final int b)
Testing MappedByteBufferInputStream and MappedByteBufferOutputStream direct stream to stream copy via...
static void main(final String args[])