[Title] added a safely convert util to the FileUtil class
authorjihoon song <jihoon80.song@samsung.com>
Wed, 7 Sep 2011 07:54:34 +0000 (16:54 +0900)
committerjihoon song <jihoon80.song@samsung.com>
Wed, 7 Sep 2011 08:55:45 +0000 (17:55 +0900)
[Type] Enhancement
[Module] common-plugins
[Priority] Minor
[CQ#] --
[Redmine#] --
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: If95155ec23c06e6d45b0e53626131f53c15ae888

com.samsung.slp.common/src/com/samsung/slp/common/util/FileUtil.java

index 1a83a17..920f7b9 100644 (file)
@@ -23,7 +23,11 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLEncoder;
 
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileSystem;
@@ -35,6 +39,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
  * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core)
  */
 public class FileUtil {
+    public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
+
     private static final int BUFFER_SIZE = 8192;
 
     /**
@@ -134,4 +140,20 @@ public class FileUtil {
         IFileSystem fileSystem = EFS.getLocalFileSystem();
         fileSystem.getStore(source).copy(fileSystem.getStore(destination), options, monitor);
     }
+    
+    /**
+     * convert URL to URI safely
+     * 
+     * @param url The source URL.
+     * @return The converted URI.
+     * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core)
+     * @throws UnsupportedEncodingException 
+     */
+    public static URI convertURLtoURI(URL url) throws URISyntaxException, UnsupportedEncodingException {
+        if (url == null) {
+            return null;
+        }
+
+        return new URI(URLEncoder.encode(url.toString(), UTF_8));
+    }
 }