Author: nextgens
Date: 2006-11-16 14:02:29 +0000 (Thu, 16 Nov 2006)
New Revision: 10941
Modified:
trunk/contrib/fec/common/build.properties
trunk/contrib/fec/common/src/com/onionnetworks/util/NativeDeployer.java
Log:
Contrib: FEC: onioncommon : fix a syntax error, indent and turn on optimizations
Modified: trunk/contrib/fec/common/build.properties
===================================================================
--- trunk/contrib/fec/common/build.properties 2006-11-15 20:25:39 UTC (rev
10940)
+++ trunk/contrib/fec/common/build.properties 2006-11-16 14:02:29 UTC (rev
10941)
@@ -29,12 +29,9 @@
tools.javadoc=${tools}/javadoc
tools.package=${package}.util
-build.compiler=jikes
+#build.compiler=jikes
javac.debug=on
-javac.optimize=off
+javac.optimize=on
javac.deprecation=off
junit.jar=${test.lib}/junit-3.7.jar
-
-
-
Modified:
trunk/contrib/fec/common/src/com/onionnetworks/util/NativeDeployer.java
===================================================================
--- trunk/contrib/fec/common/src/com/onionnetworks/util/NativeDeployer.java
2006-11-15 20:25:39 UTC (rev 10940)
+++ trunk/contrib/fec/common/src/com/onionnetworks/util/NativeDeployer.java
2006-11-16 14:02:29 UTC (rev 10941)
@@ -57,103 +57,99 @@
OS_ARCH=OS+"-x86";
else
OS_ARCH=OS+"-"+System.getProperty("os.arch").toLowerCase();
- }
}
+ public final static String NATIVE_PROPERTIES_PATH =
"lib/native.properties";
- public final static String NATIVE_PROPERTIES_PATH =
- "lib/native.properties";
+ public synchronized final static String getLibraryPath(ClassLoader cl,
String libName) {
+ long t = System.currentTimeMillis();
+ IOException iox = null;
+ /* this code avoids try {} finally {} idiom for the sake of GCJ
3.0 */
+ try {
+ String libPath = (String)
findLibraries(cl).get(libName);
+ if (libPath == null) {
+ return null;
+ }
+ try {
+ return getLocalResourcePath(cl, libPath);
+ } catch (IOException ex) {
+ iox = ex;
+ }
+ System.out.println("It took
"+(System.currentTimeMillis()-t)+
+ " millis to extract "+libName);
+ if (iox != null) {
+ iox.printStackTrace();
+ }
- public synchronized final static String getLibraryPath(ClassLoader cl,
- String libName) {
- long t = System.currentTimeMillis();
- IOException iox = null;
- /* this code avoids try {} finally {} idiom for the sake of GCJ 3.0 */
- try {
- String libPath = (String) findLibraries(cl).get(libName);
- if (libPath == null) {
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return null;
- }
- try {
- return getLocalResourcePath(cl, libPath);
- } catch (IOException ex) {
- iox = ex;
- }
- System.out.println("It took "+(System.currentTimeMillis()-t)+
- " millis to extract "+libName);
- if (iox != null) {
- iox.printStackTrace();
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
+ }
- // Since the local copy of the resource isn't stored in a temporary
- // directory, at some point we'll presumably implement version-based
- // caching rather than extracting the file every time the code is run....
- public synchronized final static String getLocalResourcePath
- (ClassLoader cl, String resourcePath) throws IOException {
+ // Since the local copy of the resource isn't stored in a temporary
+ // directory, at some point we'll presumably implement version-based
+ // caching rather than extracting the file every time the code is
run....
+ public synchronized final static String getLocalResourcePath
+ (ClassLoader cl, String resourcePath) throws IOException {
- File f = new File(System.getProperty("user.home")+
- File.separator+".onionnetworks"+File.separator+
- resourcePath);
- File parentF = f.getParentFile();
- if (parentF == null) {
- return null;
- }
- if (!parentF.exists()) {
- parentF.mkdirs();
- }
- URL url = cl.getResource(resourcePath);
- if (url == null) {
- return null;
- }
- InputStream is = url.openStream();
- f.delete(); // VERY VERY important, VM crashes w/o this :P
- OutputStream os = new FileOutputStream(f);
-
- byte[] b = new byte[1024];
- int c;
- while ((c = is.read(b)) != -1) {
- os.write(b,0,c);
- }
- is.close();
- os.flush();
- os.close();
- return f.toString();
- }
+ File f = new File(System.getProperty("user.home")+
+
File.separator+".onionnetworks"+File.separator+
+ resourcePath);
+ File parentF = f.getParentFile();
+ if (parentF == null) {
+ return null;
+ }
+ if (!parentF.exists()) {
+ parentF.mkdirs();
+ }
+ URL url = cl.getResource(resourcePath);
+ if (url == null) {
+ return null;
+ }
+ InputStream is = url.openStream();
+ f.delete(); // VERY VERY important, VM crashes w/o this
:P
+ OutputStream os = new FileOutputStream(f);
- /**
- * @return A HashMap mapping library names to paths for this os/arch.
- */
- private final static HashMap findLibraries(ClassLoader cl)
- throws IOException {
-
- HashMap libMap = new HashMap();
- // loop through all of the properties files.
- for (Enumeration en=cl.getResources(NATIVE_PROPERTIES_PATH);
- en.hasMoreElements();){
- Properties p = new Properties();
- p.load(((URL) en.nextElement()).openStream());
- // Extract the keys and loop through all of the libs.
- for (StringTokenizer st = new StringTokenizer
- (p.getProperty("com.onionnetworks.native.keys"),",");
- st.hasMoreTokens();) {
- String key = st.nextToken().trim();
- // If it matches the os and arch then add it.
- if (p.getProperty("com.onionnetworks.native."+key+".osarch").
- trim().equals(OS_ARCH)) {
+ byte[] b = new byte[1024];
+ int c;
+ while ((c = is.read(b)) != -1) {
+ os.write(b,0,c);
+ }
+ is.close();
+ os.flush();
+ os.close();
+ return f.toString();
+ }
- libMap.put(p.getProperty
-
("com.onionnetworks.native."+key+".name").trim(),
- p.getProperty
-
("com.onionnetworks.native."+key+".path").trim());
- }
- }
- }
- return libMap;
- }
+ /**
+ * @return A HashMap mapping library names to paths for this os/arch.
+ */
+ private final static HashMap findLibraries(ClassLoader cl)
+ throws IOException {
+
+ HashMap libMap = new HashMap();
+ // loop through all of the properties files.
+ for (Enumeration
en=cl.getResources(NATIVE_PROPERTIES_PATH);
+ en.hasMoreElements();){
+ Properties p = new Properties();
+ p.load(((URL) en.nextElement()).openStream());
+ // Extract the keys and loop through all of the
libs.
+ for (StringTokenizer st = new StringTokenizer
+
(p.getProperty("com.onionnetworks.native.keys"),",");
+ st.hasMoreTokens();) {
+ String key = st.nextToken().trim();
+ // If it matches the os and arch then
add it.
+ if
(p.getProperty("com.onionnetworks.native."+key+".osarch").
+ trim().equals(OS_ARCH))
{
+
+ libMap.put(p.getProperty
+
("com.onionnetworks.native."+key+".name").trim(),
+ p.getProperty
+
("com.onionnetworks.native."+key+".path").trim());
+ }
+ }
+ }
+ return libMap;
+ }
}