/[classpath]/classpath/java/net/HttpURLConnection.java
ViewVC logotype

Diff of /classpath/java/net/HttpURLConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by mark, Sun Nov 17 15:51:18 2002 UTC revision 1.10 by mark, Sun Nov 17 16:11:20 2002 UTC
# Line 495  public abstract class HttpURLConnection Line 495  public abstract class HttpURLConnection
495     */     */
496    public Permission getPermission() throws IOException    public Permission getPermission() throws IOException
497    {    {
498      return new SocketPermission (url.getHost (), "connect");      URL url = getURL();
499        String host = url.getHost();
500        int port = url.getPort();
501        if (port == -1)
502          port = 80;
503        
504        host = host + ":" + port;
505        
506        return new SocketPermission(host, "connect");
507    }    }
508    
509    /**    /**
510     * Returns the error stream if the connection failed but the server sent     * This method allows the caller to retrieve any data that might have
511     * useful data nonetheless     * been sent despite the fact that an error occurred.  For example, the
512       * HTML page sent along with a 404 File Not Found error.  If the socket
513       * is not connected, or if no error occurred or no data was returned,
514       * this method returns <code>null</code>.
515       *
516       * @return An <code>InputStream</code> for reading error data.
517     */     */
518    public InputStream getErrorStream ()    public InputStream getErrorStream ()
519    {    {
520      // FIXME: implement this      if (!connected)
521      return null;        return(null);
522        
523        int code;
524        try
525          {
526            code = getResponseCode();
527          }
528        catch(IOException e)
529          {
530            code = -1;
531          }
532        
533        if (code == -1)
534          return(null);
535        
536        if (((code/100) != 4) || ((code/100) != 5))
537          return(null);
538        
539        try
540          {
541            PushbackInputStream pbis = new PushbackInputStream(getInputStream());
542            
543            int i = pbis.read();
544            if (i == -1)
545              return(null);
546            
547            pbis.unread(i);
548            return(pbis);
549          }
550        catch(IOException e)
551          {
552            return(null);
553          }
554    }    }
555    
556    /**    /**

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26