blob: e4ff71711026935d83d76de567b24341d11d99e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package com.jogamp.common.net;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.JarURLConnection;
import java.net.URLConnection;
import org.junit.Assert;
import com.jogamp.common.os.AndroidVersion;
import com.jogamp.common.util.IOUtil;
import com.jogamp.junit.util.SingletonJunitCase;
public abstract class AssetURLConnectionBase extends SingletonJunitCase {
/** In gluegen-rt.jar */
protected static final String test_asset_rt_url = "asset:gluegen/info.txt";
protected static final String test_asset_rt_entry = "gluegen/info.txt";
protected static final String test_asset_rt2_url = "asset:/gluegen/info.txt";
/** In gluegen.test.jar */
protected static final String test_asset_test1_url = "asset:gluegen-test/info.txt";
protected static final String test_asset_test1_entry = "gluegen-test/info.txt";
protected static final Uri.Encoded test_asset_test2_rel = Uri.Encoded.cast("data/AssetURLConnectionTest.txt");
protected static final String test_asset_test2a_url = "asset:com/jogamp/common/net/data/AssetURLConnectionTest.txt";
protected static final String test_asset_test2b_url = "asset:/com/jogamp/common/net/data/AssetURLConnectionTest.txt";
protected static final String test_asset_test2_entry = "com/jogamp/common/net/data/AssetURLConnectionTest.txt";
protected static final Uri.Encoded test_asset_test3_rel = Uri.Encoded.cast("RelativeData.txt");
protected static final String test_asset_test3a_url = "asset:com/jogamp/common/net/data/RelativeData.txt";
protected static final String test_asset_test3b_url = "asset:/com/jogamp/common/net/data/RelativeData.txt";
protected static final String test_asset_test3_entry = "com/jogamp/common/net/data/RelativeData.txt";
protected static final Uri.Encoded test_asset_test4_rel = Uri.Encoded.cast("../data2/RelativeData2.txt");
protected static final String test_asset_test4a_url = "asset:com/jogamp/common/net/data2/RelativeData2.txt";
protected static final String test_asset_test4b_url = "asset:/com/jogamp/common/net/data2/RelativeData2.txt";
protected static final String test_asset_test4_entry = "com/jogamp/common/net/data2/RelativeData2.txt";
protected static void testAssetConnection(final URLConnection c, final String entry_name) throws IOException {
Assert.assertNotNull(c);
if(c instanceof AssetURLConnection) {
final AssetURLConnection ac = (AssetURLConnection) c;
Assert.assertEquals(entry_name, ac.getEntryName());
} else if(c instanceof JarURLConnection) {
final JarURLConnection jc = (JarURLConnection) c;
if(AndroidVersion.isAvailable) {
Assert.assertEquals("assets/"+entry_name, jc.getEntryName());
} else {
Assert.assertEquals(entry_name, jc.getEntryName());
}
}
final BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
try {
String line = null;
int l = 0;
while ((line = reader.readLine()) != null) {
System.err.println(c.getURL()+":"+l+"> "+line);
l++;
}
} finally {
IOUtil.close(reader, false);
}
}
}
|