From 2fddf65e3ccf8a68b1d393a41b840c62452018c2 Mon Sep 17 00:00:00 2001 From: jihoon song Date: Wed, 7 Sep 2011 16:54:34 +0900 Subject: [PATCH] [Title] added a safely convert util to the FileUtil class [Type] Enhancement [Module] common-plugins [Priority] Minor [CQ#] -- [Redmine#] -- [Problem] [Cause] [Solution] [TestCase] Change-Id: If95155ec23c06e6d45b0e53626131f53c15ae888 --- .../src/com/samsung/slp/common/util/FileUtil.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/com.samsung.slp.common/src/com/samsung/slp/common/util/FileUtil.java b/com.samsung.slp.common/src/com/samsung/slp/common/util/FileUtil.java index 1a83a17..920f7b9 100644 --- a/com.samsung.slp.common/src/com/samsung/slp/common/util/FileUtil.java +++ b/com.samsung.slp.common/src/com/samsung/slp/common/util/FileUtil.java @@ -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 } (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 } (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)); + } } -- 2.7.4