]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/src/org/simantics/fastlz/impl/OS.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / impl / OS.java
index 034096bf29cd43dfcff6b012bd0f8154f502c1d9..9531e5b17268ad3f3fbfeb4b4e1e0be9b2b94a3c 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.fastlz.impl;\r
-\r
-import java.io.Closeable;\r
-import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.net.URL;\r
-\r
-import org.simantics.fastlz.ARCHType;\r
-import org.simantics.fastlz.OSType;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class OS {\r
-\r
-    /**\r
-     * Extracts the specified source file in the specified bundle into the\r
-     * specified local directory.\r
-     * \r
-     * @param url the source URL to stream the resource from\r
-     * @param targetFile the target file to write the resource to\r
-     * @param deleteOnExit <code>true</code> to use {@link File#deleteOnExit()}\r
-     *        on the resulting file. Note that this does not guarantee that the\r
-     *        file is deleted when the JVM exits\r
-     * @return the resulting file\r
-     * @throws FileNotFoundException\r
-     */\r
-    public static File copyResource(URL url, File targetFile) throws IOException, FileNotFoundException {\r
-        FileOutputStream os = null;\r
-        InputStream is = null;\r
-        try {\r
-            if (targetFile.exists())\r
-                targetFile.delete();\r
-\r
-            is = url.openStream();\r
-            int read;\r
-            byte [] buffer = new byte [16384];\r
-            os = new FileOutputStream (targetFile);\r
-            while ((read = is.read (buffer)) != -1) {\r
-                os.write(buffer, 0, read);\r
-            }\r
-            os.close ();\r
-            is.close ();\r
-\r
-            return targetFile;\r
-        } finally {\r
-            uncheckedClose(os);\r
-            uncheckedClose(is);\r
-        }\r
-    }\r
-\r
-    public static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {\r
-        String tmpDirStr = System.getProperty("java.io.tmpdir");\r
-        if (tmpDirStr == null)\r
-            throw new NullPointerException("java.io.tmpdir property is null");\r
-        File tmpDir = new File(tmpDirStr);\r
-        File libFile = new File(tmpDir, libName);\r
-        return copyResource(libURL, libFile);\r
-    }\r
-\r
-    public static void uncheckedClose(Closeable closeable) {\r
-        try {\r
-            if (closeable != null)\r
-                closeable.close();\r
-        } catch (IOException e) {\r
-            //ignore\r
-        }\r
-    }\r
-\r
-    public static String formOsArchSuffix() {\r
-        String osName = System.getProperty("os.name");\r
-        String osArch = System.getProperty("os.arch");\r
-        OSType os = OSType.calculate();\r
-        ARCHType arch = ARCHType.calculate();\r
-\r
-        if (os == OSType.UNKNOWN)\r
-            throw new UnsatisfiedLinkError("unknown OS '" + osName + "' cannot load native fastlz library");\r
-        if (arch == ARCHType.UNKNOWN)\r
-            throw new UnsatisfiedLinkError("unknown architecture '" + osArch + "' cannot load native fastlz library");\r
-\r
-        String lib = "";\r
-        switch (os) {\r
-            case APPLE:\r
-                lib += "-darwin";\r
-                switch (arch) {\r
-                    case PPC:\r
-                        lib += "-ppc";\r
-                        break;\r
-                    case PPC_64:\r
-                        lib += "-ppc_64";\r
-                        break;\r
-                    case X86:\r
-                        lib += "-x86";\r
-                        break;\r
-                    case X86_64:\r
-                        lib += "-x86_64";\r
-                        break;\r
-                    default:\r
-                        throw new UnsatisfiedLinkError("Unsupported architecture for Apple OS: " + osArch);\r
-                }\r
-                break;\r
-            case LINUX:\r
-                lib += "-linux";\r
-                switch (arch) {\r
-                    case X86:\r
-                        lib += "-x86";\r
-                        break;\r
-                    case X86_64:\r
-                        lib += "-x86_64";\r
-                        break;\r
-                    default:\r
-                        throw new UnsatisfiedLinkError("Unsupported architecture for Linux OS: " + osArch);\r
-                }\r
-                break;\r
-            case SUN:\r
-                lib += "-sun";\r
-                switch (arch) {\r
-                    case SPARC:\r
-                        lib += "-sparc";\r
-                        break;\r
-                    case X86_64:\r
-                        lib += "-x86_64";\r
-                        break;\r
-                    default:\r
-                        throw new UnsatisfiedLinkError("Unsupported architecture for Sun OS: " + osArch);\r
-                }\r
-                break;\r
-            case WINDOWS:\r
-                lib += "-windows";\r
-                switch (arch) {\r
-                    case X86:\r
-                        lib += "-x86";\r
-                        break;\r
-                    case X86_64:\r
-                        lib += "-x86_64";\r
-                        break;\r
-                    default:\r
-                        throw new UnsatisfiedLinkError("Unsupported architecture for Windows: " + osArch);\r
-                }\r
-                break;\r
-            default:\r
-                throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
-        }\r
-        return lib;\r
-    }\r
-\r
-    public static String resolveLibName() {\r
-        String lib = "fastlz";\r
-        lib = System.mapLibraryName(lib + formOsArchSuffix());\r
-        return lib;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.fastlz.impl;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.simantics.fastlz.ARCHType;
+import org.simantics.fastlz.OSType;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class OS {
+
+    /**
+     * Extracts the specified source file in the specified bundle into the
+     * specified local directory.
+     * 
+     * @param url the source URL to stream the resource from
+     * @param targetFile the target file to write the resource to
+     * @param deleteOnExit <code>true</code> to use {@link File#deleteOnExit()}
+     *        on the resulting file. Note that this does not guarantee that the
+     *        file is deleted when the JVM exits
+     * @return the resulting file
+     * @throws FileNotFoundException
+     */
+    public static File copyResource(URL url, File targetFile) throws IOException, FileNotFoundException {
+        FileOutputStream os = null;
+        InputStream is = null;
+        try {
+            if (targetFile.exists())
+                targetFile.delete();
+
+            is = url.openStream();
+            int read;
+            byte [] buffer = new byte [16384];
+            os = new FileOutputStream (targetFile);
+            while ((read = is.read (buffer)) != -1) {
+                os.write(buffer, 0, read);
+            }
+            os.close ();
+            is.close ();
+
+            return targetFile;
+        } finally {
+            uncheckedClose(os);
+            uncheckedClose(is);
+        }
+    }
+
+    public static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {
+        String tmpDirStr = System.getProperty("java.io.tmpdir");
+        if (tmpDirStr == null)
+            throw new NullPointerException("java.io.tmpdir property is null");
+        File tmpDir = new File(tmpDirStr);
+        File libFile = new File(tmpDir, libName);
+        return copyResource(libURL, libFile);
+    }
+
+    public static void uncheckedClose(Closeable closeable) {
+        try {
+            if (closeable != null)
+                closeable.close();
+        } catch (IOException e) {
+            //ignore
+        }
+    }
+
+    public static String formOsArchSuffix() {
+        String osName = System.getProperty("os.name");
+        String osArch = System.getProperty("os.arch");
+        OSType os = OSType.calculate();
+        ARCHType arch = ARCHType.calculate();
+
+        if (os == OSType.UNKNOWN)
+            throw new UnsatisfiedLinkError("unknown OS '" + osName + "' cannot load native fastlz library");
+        if (arch == ARCHType.UNKNOWN)
+            throw new UnsatisfiedLinkError("unknown architecture '" + osArch + "' cannot load native fastlz library");
+
+        String lib = "";
+        switch (os) {
+            case APPLE:
+                lib += "-darwin";
+                switch (arch) {
+                    case PPC:
+                        lib += "-ppc";
+                        break;
+                    case PPC_64:
+                        lib += "-ppc_64";
+                        break;
+                    case X86:
+                        lib += "-x86";
+                        break;
+                    case X86_64:
+                        lib += "-x86_64";
+                        break;
+                    default:
+                        throw new UnsatisfiedLinkError("Unsupported architecture for Apple OS: " + osArch);
+                }
+                break;
+            case LINUX:
+                lib += "-linux";
+                switch (arch) {
+                    case X86:
+                        lib += "-x86";
+                        break;
+                    case X86_64:
+                        lib += "-x86_64";
+                        break;
+                    default:
+                        throw new UnsatisfiedLinkError("Unsupported architecture for Linux OS: " + osArch);
+                }
+                break;
+            case SUN:
+                lib += "-sun";
+                switch (arch) {
+                    case SPARC:
+                        lib += "-sparc";
+                        break;
+                    case X86_64:
+                        lib += "-x86_64";
+                        break;
+                    default:
+                        throw new UnsatisfiedLinkError("Unsupported architecture for Sun OS: " + osArch);
+                }
+                break;
+            case WINDOWS:
+                lib += "-windows";
+                switch (arch) {
+                    case X86:
+                        lib += "-x86";
+                        break;
+                    case X86_64:
+                        lib += "-x86_64";
+                        break;
+                    default:
+                        throw new UnsatisfiedLinkError("Unsupported architecture for Windows: " + osArch);
+                }
+                break;
+            default:
+                throw new UnsatisfiedLinkError("Unsupported operating system: " + os);
+        }
+        return lib;
+    }
+
+    public static String resolveLibName() {
+        String lib = "fastlz";
+        lib = System.mapLibraryName(lib + formOsArchSuffix());
+        return lib;
+    }
+
+}