]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.team.ui/src/org/simantics/team/Utils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / Utils.java
index 59c9329548d9bf46be82a12a6091ca8a57f58ce5..db12a1cb7f52aeda222dc43a2952ea223f25db68 100644 (file)
@@ -1,87 +1,87 @@
-package org.simantics.team;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.nio.ByteBuffer;\r
-import java.nio.CharBuffer;\r
-import java.nio.charset.CharacterCodingException;\r
-import java.nio.charset.Charset;\r
-import java.nio.charset.CodingErrorAction;\r
-\r
-import org.eclipse.core.runtime.preferences.InstanceScope;\r
-import org.eclipse.jface.preference.IPreferenceStore;\r
-import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.team.ui.Preferences;\r
-\r
-public class Utils {\r
-    public static final File getNewFolder(int index, String prefix, String suffix) {\r
-        File toFolder;\r
-        do {\r
-            toFolder = new File(prefix + index + suffix);\r
-        } while (toFolder.exists());\r
-        return toFolder;\r
-    }\r
-    private static final Charset ASCII = Charset.forName("US-ASCII");\r
-    protected static final Charset UTF8 = Charset.forName("UTF-8");\r
-    public static final String bytesToStringASCII(byte[] bytes, int offset, int length)\r
-    throws IOException {\r
-        return bytesToString(bytes, offset, length, ASCII);\r
-    }\r
-    public static final String bytesToStringUTF8(byte[] bytes, int offset, int length)\r
-    throws IOException {\r
-        return bytesToString(bytes, offset, length, UTF8);\r
-    }\r
-    public static final String bytesToString(byte[] bytes, int offset, int length, Charset charset)\r
-    throws IOException {\r
-        if (bytes == null || offset < 0 || offset > length - 1 || length < 0 || length > bytes.length)\r
-            return null;\r
-        ByteBuffer bbuf = ByteBuffer.wrap(bytes, offset, length);\r
-        CharBuffer cbuf;\r
-        String s = null;\r
-        try {\r
-            cbuf =  charset.newDecoder().decode(bbuf);\r
-            s = cbuf.toString();\r
-        } catch (CharacterCodingException e) {\r
-            bbuf.rewind();\r
-            try {\r
-                cbuf = charset.newDecoder()\r
-                .onMalformedInput(CodingErrorAction.REPLACE)\r
-                .onUnmappableCharacter(CodingErrorAction.REPLACE)\r
-                .decode(bbuf);\r
-                s = cbuf.toString();\r
-            } catch (CharacterCodingException e1) {\r
-                throw new IOException("String conversion error.", e1);\r
-            }\r
-        }\r
-        return s;\r
-    }\r
-    public static final File getTeamFolder() \r
-    throws DatabaseException {\r
-        IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);\r
-        String currentTeamFolder = store.getString(Preferences.CURRENT_TEAM_FOLDER);\r
-        if (!currentTeamFolder.equals(""))\r
-            return new File(currentTeamFolder);\r
-        String name = System.getProperty("staging.team.folder");\r
-        if (null != name && !name.equals(""))\r
-            return new File(name);\r
-        String folder = System.getProperty("java.io.tmpdir");\r
-        if (null == folder || folder.equals(""))\r
-            throw new DatabaseException("Could not get team folder path.");\r
-        return null;\r
-//        IProduct product = Platform.getProduct();\r
-//        if (null != product)\r
-//            name = "Team " + product.getName();\r
-//        else\r
-//          name = "Default Team Folder";\r
-//        return new File(folder, name);\r
-    }\r
-    public static final void setTeamFolder(File teamFolder) \r
-    throws DatabaseException {\r
-        IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);\r
-        if (null == teamFolder)\r
-            store.setValue(Preferences.CURRENT_TEAM_FOLDER, "");\r
-        else\r
-            store.setValue(Preferences.CURRENT_TEAM_FOLDER, teamFolder.getAbsolutePath());\r
-    }\r
-}\r
+package org.simantics.team;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CodingErrorAction;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.team.ui.Preferences;
+
+public class Utils {
+    public static final File getNewFolder(int index, String prefix, String suffix) {
+        File toFolder;
+        do {
+            toFolder = new File(prefix + index + suffix);
+        } while (toFolder.exists());
+        return toFolder;
+    }
+    private static final Charset ASCII = Charset.forName("US-ASCII");
+    protected static final Charset UTF8 = Charset.forName("UTF-8");
+    public static final String bytesToStringASCII(byte[] bytes, int offset, int length)
+    throws IOException {
+        return bytesToString(bytes, offset, length, ASCII);
+    }
+    public static final String bytesToStringUTF8(byte[] bytes, int offset, int length)
+    throws IOException {
+        return bytesToString(bytes, offset, length, UTF8);
+    }
+    public static final String bytesToString(byte[] bytes, int offset, int length, Charset charset)
+    throws IOException {
+        if (bytes == null || offset < 0 || offset > length - 1 || length < 0 || length > bytes.length)
+            return null;
+        ByteBuffer bbuf = ByteBuffer.wrap(bytes, offset, length);
+        CharBuffer cbuf;
+        String s = null;
+        try {
+            cbuf =  charset.newDecoder().decode(bbuf);
+            s = cbuf.toString();
+        } catch (CharacterCodingException e) {
+            bbuf.rewind();
+            try {
+                cbuf = charset.newDecoder()
+                .onMalformedInput(CodingErrorAction.REPLACE)
+                .onUnmappableCharacter(CodingErrorAction.REPLACE)
+                .decode(bbuf);
+                s = cbuf.toString();
+            } catch (CharacterCodingException e1) {
+                throw new IOException("String conversion error.", e1);
+            }
+        }
+        return s;
+    }
+    public static final File getTeamFolder() 
+    throws DatabaseException {
+        IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
+        String currentTeamFolder = store.getString(Preferences.CURRENT_TEAM_FOLDER);
+        if (!currentTeamFolder.equals(""))
+            return new File(currentTeamFolder);
+        String name = System.getProperty("staging.team.folder");
+        if (null != name && !name.equals(""))
+            return new File(name);
+        String folder = System.getProperty("java.io.tmpdir");
+        if (null == folder || folder.equals(""))
+            throw new DatabaseException("Could not get team folder path.");
+        return null;
+//        IProduct product = Platform.getProduct();
+//        if (null != product)
+//            name = "Team " + product.getName();
+//        else
+//          name = "Default Team Folder";
+//        return new File(folder, name);
+    }
+    public static final void setTeamFolder(File teamFolder) 
+    throws DatabaseException {
+        IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
+        if (null == teamFolder)
+            store.setValue(Preferences.CURRENT_TEAM_FOLDER, "");
+        else
+            store.setValue(Preferences.CURRENT_TEAM_FOLDER, teamFolder.getAbsolutePath());
+    }
+}