From e3661df583715205926f8d36baa6b6b6714b1fab Mon Sep 17 00:00:00 2001 From: mark Date: Sun, 17 Nov 2002 16:16:52 +0000 Subject: [PATCH] * java/net/HttpURLConnection.java ((getPermission): Take port into consideration. (getErrorStream): Implement. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59196 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 6 ++++ libjava/java/net/HttpURLConnection.java | 55 ++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index a5b63e5..dd3f6eb 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,11 @@ 2002-11-17 Mark Wielaard + * java/net/HttpURLConnection.java ((getPermission): Take port + into consideration. + (getErrorStream): Implement. + +2002-11-17 Mark Wielaard + * java/net/HttpURLConnection.java: Merge with GNU Classpath. 2002-11-16 Mark Wielaard diff --git a/libjava/java/net/HttpURLConnection.java b/libjava/java/net/HttpURLConnection.java index 85a3ea4..e914b19 100644 --- a/libjava/java/net/HttpURLConnection.java +++ b/libjava/java/net/HttpURLConnection.java @@ -495,17 +495,62 @@ public abstract class HttpURLConnection extends URLConnection */ public Permission getPermission() throws IOException { - return new SocketPermission (url.getHost (), "connect"); + URL url = getURL(); + String host = url.getHost(); + int port = url.getPort(); + if (port == -1) + port = 80; + + host = host + ":" + port; + + return new SocketPermission(host, "connect"); } /** - * Returns the error stream if the connection failed but the server sent - * useful data nonetheless + * This method allows the caller to retrieve any data that might have + * been sent despite the fact that an error occurred. For example, the + * HTML page sent along with a 404 File Not Found error. If the socket + * is not connected, or if no error occurred or no data was returned, + * this method returns null. + * + * @return An InputStream for reading error data. */ public InputStream getErrorStream () { - // FIXME: implement this - return null; + if (!connected) + return(null); + + int code; + try + { + code = getResponseCode(); + } + catch(IOException e) + { + code = -1; + } + + if (code == -1) + return(null); + + if (((code/100) != 4) || ((code/100) != 5)) + return(null); + + try + { + PushbackInputStream pbis = new PushbackInputStream(getInputStream()); + + int i = pbis.read(); + if (i == -1) + return(null); + + pbis.unread(i); + return(pbis); + } + catch(IOException e) + { + return(null); + } } /** -- 2.7.4