From 235f8b1cbff8ed13071d5c19c0be492c0b25cb78 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 17 Mar 2012 21:15:49 +0100 Subject: Add 'asset' URLConnection; IOUtil uses URLConnection / incr. effeciency; Android ClassLoaderUtil cleanup; - Add 'asset' URLConnection - Please read API doc 'PiggybackURLConnection' and 'AssetURLConnection' - Solves generic resource handling where platform locations may differ, ie ClassLoader lookup on Android in the 'assets/' subfolder. - New Android 'AssetDexClassLoader' uses 'assets/' folder for findResource(..) - aapt.signed (our APK ant task) - uses 'assets/' folder - adds the 'assetsdir' attribute allowing to copy other assets into the APK - IOUtil uses URLConnection / incr. effeciency - using URLConnection on all getResource(..) since URL is connected anyways for validation and URLConnection can be used by caller right away - String getRelativeOf(URL, String) -> URL getRelativeOf(URL, String) - preserves scheme, authority, etc - simple parentOf handling, more efficient - reusing new 'asset' protocol impl. - Android ClassLoaderUtil cleanup; - Use createClassLoader(..) impl for build-in static jogamp and user APKs, which removes code redundancy Tests: New code path, especially 'assets' are covered by new unit tests, no regressions on Linux. --- src/junit/com/jogamp/common/util/TestIOUtil01.java | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/junit/com/jogamp/common/util') diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java index 47fa1e9..b75127c 100644 --- a/src/junit/com/jogamp/common/util/TestIOUtil01.java +++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java @@ -35,13 +35,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.net.URL; +import java.net.URLConnection; import java.nio.ByteBuffer; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; -import org.junit.AfterClass; import org.junit.Test; import com.jogamp.common.os.MachineDescription; @@ -69,9 +67,9 @@ public class TestIOUtil01 extends JunitTracer { @Test public void testCopyStream01Array() throws IOException { - URL url = IOUtil.getResource(this.getClass(), tfilename); - Assert.assertNotNull(url); - final BufferedInputStream bis = new BufferedInputStream( url.openStream() ); + URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(urlConn); + final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); final byte[] bb; try { bb = IOUtil.copyStream2ByteArray( bis ); @@ -85,9 +83,9 @@ public class TestIOUtil01 extends JunitTracer { @Test public void testCopyStream02Buffer() throws IOException { - URL url = IOUtil.getResource(this.getClass(), tfilename); - Assert.assertNotNull(url); - final BufferedInputStream bis = new BufferedInputStream( url.openStream() ); + URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(urlConn); + final BufferedInputStream bis = new BufferedInputStream( urlConn.getInputStream() ); final ByteBuffer bb; try { bb = IOUtil.copyStream2ByteBuffer( bis ); @@ -103,15 +101,15 @@ public class TestIOUtil01 extends JunitTracer { @Test public void testCopyStream03Buffer() throws IOException { final String tfilename2 = "./test2.bin" ; - URL url1 = IOUtil.getResource(this.getClass(), tfilename); - Assert.assertNotNull(url1); + URLConnection urlConn1 = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(urlConn1); File file2 = new File(tfilename2); - IOUtil.copyURL2File(url1, file2); - URL url2 = IOUtil.getResource(this.getClass(), tfilename2); - Assert.assertNotNull(url2); + IOUtil.copyURLConn2File(urlConn1, file2); + URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2); + Assert.assertNotNull(urlConn2); - final BufferedInputStream bis = new BufferedInputStream( url2.openStream() ); + final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() ); final ByteBuffer bb; try { bb = IOUtil.copyStream2ByteBuffer( bis ); -- cgit v1.2.3