From 12571b1f964b2fcbae5f66b6307c31854ed8c0d5 Mon Sep 17 00:00:00 2001
From: Warren Levy <warrenl@cygnus.com>
Date: Fri, 23 Apr 1999 16:36:22 +0000
Subject: Makefile.am: Added URLDecoder and URLEncoder.

	* Makefile.am: Added URLDecoder and URLEncoder.
	* Makefile.in: Rebuilt.
	* java/net/ServerSocket.java (setSocketFactory): Renamed from
	setSocketImplFactory to match spec.
	* java/net/Socket.java (getSoLinger): Changed return type to
	match spec.
	* java/net/URLDecoder.java: New file.
	* java/net/URLEncoder.java: New file.

From-SVN: r26605
---
 libjava/java/net/ServerSocket.java |  2 +-
 libjava/java/net/Socket.java       |  2 +-
 libjava/java/net/URLDecoder.java   | 48 ++++++++++++++++++++++++++
 libjava/java/net/URLEncoder.java   | 71 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 libjava/java/net/URLDecoder.java
 create mode 100644 libjava/java/net/URLEncoder.java

(limited to 'libjava/java/net')

diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java
index e4b5069..4dcd9d6 100644
--- a/libjava/java/net/ServerSocket.java
+++ b/libjava/java/net/ServerSocket.java
@@ -96,7 +96,7 @@ public class ServerSocket
     return impl.toString();
   }
 
-  public static void setSocketImplFactory (SocketImplFactory fac)
+  public static void setSocketFactory (SocketImplFactory fac)
     throws IOException
   {
     factory = fac;
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index 8c027d9..8446b22 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -156,7 +156,7 @@ public class Socket
     throw new InternalError("Socket.setSoLinger not implemented");
   }
 
-  public boolean getSoLinger() throws SocketException
+  public int getSoLinger() throws SocketException
   {
     throw new InternalError("Socket.getSoLinger not implemented");
   }
diff --git a/libjava/java/net/URLDecoder.java b/libjava/java/net/URLDecoder.java
new file mode 100644
index 0000000..40d47b7
--- /dev/null
+++ b/libjava/java/net/URLDecoder.java
@@ -0,0 +1,48 @@
+// URLDecoder.java - Provides a method for decoding strings according to
+//		     application/x-www-form-urlencoded MIME type.
+
+/* Copyright (C) 1999  Cygnus Solutions
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+package java.net;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author Warren Levy <warrenl@cygnus.com>
+ * @date April 22, 1999.
+ */
+
+/**
+ * Written using on-line Java Platform 1.2 API Specification.
+ * Status:  Believed complete and correct.
+ */
+
+// JDK1.2
+public class URLDecoder
+{
+  // This method, per the JCL, is conservative in that it encodes
+  // some "allowable" characters as % triplets.
+  public static String decode(String s) throws Exception
+  {
+    String str = s.replace('+', ' ');
+    String result = "";
+    int i;
+    int start = 0;
+    while ((i = str.indexOf('%', start)) >= 0)
+      {
+	result = result + str.substring(start, i) +
+		 (char) Integer.parseInt(str.substring(i + 1, i + 3), 16);
+	start = i + 3;
+      }
+
+    if (start < str.length())
+      result = result + str.substring(start);
+
+    return result;
+  }
+}
diff --git a/libjava/java/net/URLEncoder.java b/libjava/java/net/URLEncoder.java
new file mode 100644
index 0000000..83295ea
--- /dev/null
+++ b/libjava/java/net/URLEncoder.java
@@ -0,0 +1,71 @@
+// URLEncoder.java - Provides a method for encoding strings according to
+//		     application/x-www-form-urlencoded MIME type.
+
+/* Copyright (C) 1999  Cygnus Solutions
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+package java.net;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author Warren Levy <warrenl@cygnus.com>
+ * @date April 22, 1999.
+ */
+
+/**
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * Status:  Believed complete and correct.
+ */
+
+public class URLEncoder
+{
+  // This method, per the JCL, is conservative in that it encodes
+  // some "allowable" characters as % triplets.
+  public static String encode(String s)
+  {
+    // Get the bytes in ISO-Latin-1 (i.e. 8859_1) per the JCL.
+    // Even though it is the default in most cases, it's specified here
+    // just in case System.getProperty("file.encoding") is not "8859_1".
+    String result = "";
+    try
+      {
+	byte[] buf = s.getBytes("8859_1");
+	int start = 0;
+	for (int i = 0; i < buf.length; i++)
+	  // For efficiency, check the byte in order of most likely
+	  // possibility so as to minimize the number of comparisons.
+	  // Hence, exclude all the alphanumeric & allowed special chars first.
+	  if ((buf[i] >= 'a' && buf[i] <= 'z') ||
+	      (buf[i] >= 'A' && buf[i] <= 'Z') ||
+	      (buf[i] >= '0' && buf[i] <= '9') ||
+	      buf[i] == '-' || buf[i] == '_' || buf[i] == '.' || buf[i] == '*')
+	    ; // This is the most likely case so exclude first for efficiency.
+	  else if (buf[i] == ' ')
+	    buf[i] = (byte) '+';  // Replace space char with plus symbol.
+	  else
+	    {
+	      result = result + new String(buf, start, i - start, "8859_1") +
+			"%" + Integer.toHexString(((int) buf[i]) & 0xFF);
+	      start = i + 1;
+	    }
+
+	// Append remainder of allowable chars from the string, if any.
+	if (start < buf.length)
+	  result = result +
+		   new String(buf, start, buf.length - start, "8859_1");
+      }
+    catch (UnsupportedEncodingException ex)
+      {
+	// This should never happen as "8859_1" is the default encoding.
+	return s;
+      }
+
+    return result;
+  }
+}
-- 
cgit v1.1