summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-19 09:48:28 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-19 09:48:28 +0000
commit3ab59dff186611f8188cee625398bb4f1a6d0d59 (patch)
tree6e49cd962d755a57d5142556aa599f42794ded46 /libjava
parent0b9ac1e0f1c7bfbbb0b7f9060b56a4c4d6905b2c (diff)
downloadgcc-3ab59dff186611f8188cee625398bb4f1a6d0d59.tar.gz
2003-12-19 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/jar/Handler.java (parseURL): New method. (toExternalForm): New method. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74827 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog6
-rw-r--r--libjava/gnu/java/net/protocol/jar/Handler.java82
2 files changed, 88 insertions, 0 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 231cf35a752..aeca31281e8 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-19 Michael Koch <konqueror@gmx.de>
+
+ * gnu/java/net/protocol/jar/Handler.java
+ (parseURL): New method.
+ (toExternalForm): New method.
+
2003-12-18 Fernando Nasser <fnasser@redhat.com>
* java/awt/List.java (replaceItem): Prevent selection to move with
diff --git a/libjava/gnu/java/net/protocol/jar/Handler.java b/libjava/gnu/java/net/protocol/jar/Handler.java
index eaad0f48ba5..76ba6fddf3b 100644
--- a/libjava/gnu/java/net/protocol/jar/Handler.java
+++ b/libjava/gnu/java/net/protocol/jar/Handler.java
@@ -68,4 +68,86 @@ public class Handler extends URLStreamHandler
{
return new Connection(url);
}
+
+ /**
+ * This method overrides URLStreamHandler's for parsing url of protocol "jar"
+ *
+ * @param url The URL object in which to store the results
+ * @param url_string The String-ized URL to parse
+ * @param start The position in the string to start scanning from
+ * @param end The position in the string to stop scanning
+ */
+ protected void parseURL (URL url, String url_string, int start, int end)
+ {
+ // This method does not throw an exception or return a value. Thus our
+ // strategy when we encounter an error in parsing is to return without
+ // doing anything.
+ String file = url.getFile();
+
+ if (file != null
+ && file != "")
+ { //has context url
+ url_string = url_string.substring (start, end);
+ if (url_string.startsWith("/"))
+ { //url string is an absolute path
+ int idx = file.lastIndexOf ("!/");
+ if (idx == -1) //context path is weird
+ file = file + "!" + url_string;
+ else
+ file = file.substring (0, idx + 1) + url_string;
+ }
+ else
+ {
+ int idx = file.lastIndexOf ("/");
+ if (idx == -1) //context path is weird
+ file = "/" + url_string;
+ else if (idx == (file.length() - 1))
+ //just concatenate two parts
+ file = file + url_string;
+ else
+ // according to Java API Documentation, here is a little different
+ // with URLStreamHandler.parseURL
+ // but JDK seems doesn't handle it well
+ file = file + "/" + url_string;
+ }
+
+ setURL (url, "jar", url.getHost(), url.getPort(), file, null);
+ return;
+ }
+
+ // Bunches of things should be true. Make sure.
+ if (end < start)
+ return;
+ if (end - start < 2)
+ return;
+ if (start > url_string.length())
+ return;
+
+ // Skip remains of protocol
+ url_string = url_string.substring (start, end);
+
+ if (!url.getProtocol().equals ("jar") )
+ return;
+
+ setURL (url, "jar", url.getHost(), url.getPort(), url_string, null);
+ }
+
+ /**
+ * This method converts a Jar URL object into a String.
+ *
+ * @param url The URL object to convert
+ */
+ protected String toExternalForm (URL url)
+ {
+ String file = url.getFile();
+
+ // return "jar:" + file;
+ // Performance!!:
+ // Do the concatenation manually to avoid resize StringBuffer's
+ // internal buffer.
+ StringBuffer sb = new StringBuffer (file.length() + 5);
+ sb.append ("jar:");
+ sb.append (file);
+ return sb.toString();
+ }
}