29import java.io.BufferedInputStream;
30import java.io.BufferedOutputStream;
32import java.io.FileOutputStream;
33import java.io.IOException;
34import java.io.OutputStream;
35import java.net.URISyntaxException;
36import java.net.URLConnection;
37import java.nio.ByteBuffer;
38import java.util.Arrays;
40import org.jau.io.IOUtil;
41import org.jau.lang.ExceptionUtils;
42import org.jau.sys.MachineDataInfo;
43import org.jau.sys.PlatformProps;
44import org.junit.AfterClass;
45import org.junit.Assert;
46import org.junit.BeforeClass;
47import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
51import jau.test.junit.util.JunitTracer;
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 static final int tsz = machine.pageSizeInBytes() + machine.pageSizeInBytes() / 2 ;
58 static final byte[] orig =
new byte[tsz];
59 static final String tfilename =
"./test.bin" ;
62 public static void setup() throws IOException {
63 final File tfile =
new File(tfilename);
65 final OutputStream tout =
new BufferedOutputStream(
new FileOutputStream(tfile));
66 for(
int i=0; i<tsz; i++) {
67 final byte b = (byte) (i%256);
76 final File tfile =
new File(tfilename);
83 final String input =
"./dummy/nop/../a.txt";
84 final String expected =
"dummy/a.txt";
88 final String input =
"../dummy/nop/../a.txt";
89 final String expected =
"../dummy/a.txt";
93 final String input =
".././dummy/nop/../a.txt";
94 final String expected =
"../dummy/a.txt";
98 final String input =
"./../dummy/nop/../a.txt";
99 final String expected =
"../dummy/a.txt";
103 final String input =
"../dummy/./nop/../a.txt";
104 final String expected =
"../dummy/a.txt";
108 final String input =
"/dummy/nop/./../a.txt";
109 final String expected =
"/dummy/a.txt";
113 final String input =
"dummy/../nop/./.././aaa/bbb/../../a.txt";
114 final String expected =
"a.txt";
118 final String input =
"/dummy/../nop/./.././aaa/bbb/././ccc/../../../a.txt";
119 final String expected =
"/a.txt";
123 URISyntaxException use =
null;
126 final String input =
"../../error.txt";
127 final String expected =
"error.txt";
129 System.err.println(
"input : "+input);
130 System.err.println(
"expected: "+expected);
131 System.err.println(
"result : "+result);
132 Assert.assertEquals(expected, result);
133 }
catch (
final URISyntaxException _use) {
137 Assert.assertNotNull(
"URISyntaxException expected", use);
140 URISyntaxException use =
null;
143 final String input =
".././a/../../error.txt";
144 final String expected =
"error.txt";
146 System.err.println(
"input : "+input);
147 System.err.println(
"expected: "+expected);
148 System.err.println(
"result : "+result);
149 Assert.assertEquals(expected, result);
150 }
catch (
final URISyntaxException _use) {
154 Assert.assertNotNull(
"URISyntaxException expected", use);
160 final URLConnection urlConn =
IOUtil.
getResource(tfilename, this.getClass().getClassLoader(), this.getClass());
161 Assert.assertNotNull(urlConn);
162 final BufferedInputStream bis =
new BufferedInputStream( urlConn.getInputStream() );
169 Assert.assertEquals(
"Byte number not equal orig vs array", orig.length, bb.length);
170 Assert.assertTrue(
"Bytes not equal orig vs array", Arrays.equals(orig, bb));
176 final URLConnection urlConn =
IOUtil.
getResource(tfilename, this.getClass().getClassLoader(), this.getClass());
177 Assert.assertNotNull(urlConn);
178 final BufferedInputStream bis =
new BufferedInputStream( urlConn.getInputStream() );
185 Assert.assertEquals(
"Byte number not equal orig vs buffer", orig.length, bb.limit());
187 for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
188 Assert.assertTrue(
"Bytes not equal orig vs array", 0>i);
193 final String tfilename2 =
"./test2.bin" ;
194 final URLConnection urlConn1 =
IOUtil.
getResource(tfilename, this.getClass().getClassLoader(), this.getClass());
195 Assert.assertNotNull(urlConn1);
197 final File file2 =
new File(tfilename2);
198 file2.deleteOnExit();
201 final URLConnection urlConn2 =
IOUtil.
getResource(tfilename2, this.getClass().getClassLoader(), this.getClass());
202 Assert.assertNotNull(urlConn2);
204 final BufferedInputStream bis =
new BufferedInputStream( urlConn2.getInputStream() );
211 Assert.assertEquals(
"Byte number not equal orig vs buffer", orig.length, bb.limit());
213 for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ;
214 Assert.assertTrue(
"Bytes not equal orig vs array", 0>i);
220 public static void main(
final String args[])
throws IOException {
222 org.junit.runner.JUnitCore.
main(tstname);
void test11CopyStream01Array()
static void main(final String args[])
void test13CopyStream03Buffer()
void test01CleanPathString()
void test12CopyStream02Buffer()
static int copyURLConn2File(final URLConnection conn, final File outFile)
Copy the specified URL resource to the specified output file.
static String cleanPathString(String path)
static byte[] copyStream2ByteArray(InputStream stream)
Copy the specified input stream to a byte array, which is being returned.
static URLConnection getResource(final String resourcePath, final ClassLoader classLoader, final Class<?> relContext)
Locating a resource using getResource(String, ClassLoader):
static void close(final Closeable stream, final boolean throwRuntimeException)
static ByteBuffer copyStream2ByteBuffer(final InputStream stream)
Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
static void dumpThrowable(final String additionalDescr, final Throwable t)
Dumps a Throwable to System.err in a decorating message including the current thread name,...
Machine data description for alignment and size onle, see com.jogamp.gluegen.