src/java.base/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java
changeset 55711 0c143aaa2c99
parent 53018 8bf9268df0e2
child 57879 095c2f21dd10
equal deleted inserted replaced
55710:18130ed28231 55711:0c143aaa2c99
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    34 import java.io.OutputStream;
    34 import java.io.OutputStream;
    35 import java.io.BufferedInputStream;
    35 import java.io.BufferedInputStream;
    36 import java.io.FilterInputStream;
    36 import java.io.FilterInputStream;
    37 import java.io.FilterOutputStream;
    37 import java.io.FilterOutputStream;
    38 import java.io.FileNotFoundException;
    38 import java.io.FileNotFoundException;
       
    39 import java.net.MalformedURLException;
    39 import java.net.URL;
    40 import java.net.URL;
    40 import java.net.SocketPermission;
    41 import java.net.SocketPermission;
    41 import java.net.UnknownHostException;
    42 import java.net.UnknownHostException;
    42 import java.net.InetSocketAddress;
    43 import java.net.InetSocketAddress;
    43 import java.net.URI;
    44 import java.net.URI;
    46 import java.util.StringTokenizer;
    47 import java.util.StringTokenizer;
    47 import java.util.Iterator;
    48 import java.util.Iterator;
    48 import java.security.Permission;
    49 import java.security.Permission;
    49 import java.util.Properties;
    50 import java.util.Properties;
    50 import sun.net.NetworkClient;
    51 import sun.net.NetworkClient;
       
    52 import sun.net.util.IPAddressUtil;
    51 import sun.net.www.MessageHeader;
    53 import sun.net.www.MessageHeader;
    52 import sun.net.www.MeteredStream;
    54 import sun.net.www.MeteredStream;
    53 import sun.net.www.URLConnection;
    55 import sun.net.www.URLConnection;
    54 import sun.net.www.protocol.http.HttpURLConnection;
    56 import sun.net.www.protocol.http.HttpURLConnection;
    55 import sun.net.ftp.FtpClient;
    57 import sun.net.ftp.FtpClient;
   155                 ftp.close();
   157                 ftp.close();
   156             }
   158             }
   157         }
   159         }
   158     }
   160     }
   159 
   161 
       
   162     static URL checkURL(URL u) throws IllegalArgumentException {
       
   163         if (u != null) {
       
   164             if (u.toExternalForm().indexOf('\n') > -1) {
       
   165                 Exception mfue = new MalformedURLException("Illegal character in URL");
       
   166                 throw new IllegalArgumentException(mfue.getMessage(), mfue);
       
   167             }
       
   168         }
       
   169         String s = IPAddressUtil.checkAuthority(u);
       
   170         if (s != null) {
       
   171             Exception mfue = new MalformedURLException(s);
       
   172             throw new IllegalArgumentException(mfue.getMessage(), mfue);
       
   173         }
       
   174         return u;
       
   175     }
       
   176 
   160     /**
   177     /**
   161      * Creates an FtpURLConnection from a URL.
   178      * Creates an FtpURLConnection from a URL.
   162      *
   179      *
   163      * @param   url     The {@code URL} to retrieve or store.
   180      * @param   url     The {@code URL} to retrieve or store.
   164      */
   181      */
   168 
   185 
   169     /**
   186     /**
   170      * Same as FtpURLconnection(URL) with a per connection proxy specified
   187      * Same as FtpURLconnection(URL) with a per connection proxy specified
   171      */
   188      */
   172     FtpURLConnection(URL url, Proxy p) {
   189     FtpURLConnection(URL url, Proxy p) {
   173         super(url);
   190         super(checkURL(url));
   174         instProxy = p;
   191         instProxy = p;
   175         host = url.getHost();
   192         host = url.getHost();
   176         port = url.getPort();
   193         port = url.getPort();
   177         String userInfo = url.getUserInfo();
   194         String userInfo = url.getUserInfo();
   178 
   195