jdk/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java
author robm
Fri, 01 Aug 2014 15:36:23 +0100
changeset 25805 0bc2aa4aadbe
parent 7668 d4a77089c587
permissions -rw-r--r--
8031435: Ftp download does not work properly for ftp user without password Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7022
diff changeset
     2
 * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4155
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4155
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4155
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4155
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4155
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * FTP stream opener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package sun.net.www.protocol.ftp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.FilterInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.FilterOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.InetSocketAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.ProxySelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.Permission;
7022
1066bfde0f5e 6993490: SocketTimeoutException on HTTP keep-alive connections
chegar
parents: 5506
diff changeset
    49
import sun.net.NetworkClient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.net.www.MessageHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.net.www.MeteredStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.net.www.URLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.net.www.protocol.http.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.net.ftp.FtpClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.net.ftp.FtpProtocolException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.net.ProgressSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.net.ProgressMonitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * This class Opens an FTP input (or output) stream given a URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * It works as a one shot FTP transfer :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <LI>Login</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <LI>Get (or Put) the file</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <LI>Disconnect</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * You should not have to use it directly in most cases because all will be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * in a abstract layer. Here is an example of how to use the class :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>URL url = new URL("ftp://ftp.sun.com/pub/test.txt");<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * UrlConnection con = url.openConnection();<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * InputStream is = con.getInputStream();<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * ...<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * is.close();</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see sun.net.ftp.FtpClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
public class FtpURLConnection extends URLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // In case we have to use proxies, we use HttpURLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    HttpURLConnection http = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private Proxy instProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    InputStream is = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    OutputStream os = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    FtpClient ftp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    Permission permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    String password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    String user;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    String host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    String pathname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    String filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    String fullpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static final int NONE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static final int ASCII = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static final int BIN = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static final int DIR = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    int type = NONE;
7022
1066bfde0f5e 6993490: SocketTimeoutException on HTTP keep-alive connections
chegar
parents: 5506
diff changeset
   106
    /* Redefine timeouts from java.net.URLConnection as we need -1 to mean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * not set. This is to ensure backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
7022
1066bfde0f5e 6993490: SocketTimeoutException on HTTP keep-alive connections
chegar
parents: 5506
diff changeset
   109
    private int connectTimeout = NetworkClient.DEFAULT_CONNECT_TIMEOUT;;
1066bfde0f5e 6993490: SocketTimeoutException on HTTP keep-alive connections
chegar
parents: 5506
diff changeset
   110
    private int readTimeout = NetworkClient.DEFAULT_READ_TIMEOUT;;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * For FTP URLs we need to have a special InputStream because we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * need to close 2 sockets after we're done with it :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *  - The Data socket (for the file).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *   - The command socket (FtpClient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Since that's the only class that needs to see that, it is an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected class FtpInputStream extends FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        FtpClient ftp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        FtpInputStream(FtpClient cl, InputStream fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            super(new BufferedInputStream(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            ftp = cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   126
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            super.close();
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   129
            if (ftp != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   130
                ftp.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * For FTP URLs we need to have a special OutputStream because we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * need to close 2 sockets after we're done with it :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *  - The Data socket (for the file).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *   - The command socket (FtpClient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Since that's the only class that needs to see that, it is an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected class FtpOutputStream extends FilterOutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        FtpClient ftp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        FtpOutputStream(FtpClient cl, OutputStream fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            super(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            ftp = cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   149
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            super.close();
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   152
            if (ftp != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   153
                ftp.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Creates an FtpURLConnection from a URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param   url     The <code>URL</code> to retrieve or store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public FtpURLConnection(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this(url, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Same as FtpURLconnection(URL) with a per connection proxy specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    FtpURLConnection(URL url, Proxy p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        instProxy = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        host = url.getHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        port = url.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        String userInfo = url.getUserInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (userInfo != null) { // get the user and password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            int delimiter = userInfo.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (delimiter == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                user = ParseUtil.decode(userInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                password = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                user = ParseUtil.decode(userInfo.substring(0, delimiter++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                password = ParseUtil.decode(userInfo.substring(delimiter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private void setTimeouts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (ftp != null) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   191
            if (connectTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                ftp.setConnectTimeout(connectTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   193
            }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   194
            if (readTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                ftp.setReadTimeout(readTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   196
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Connects to the FTP server and logs in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @throws  FtpLoginException if the login is unsuccessful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @throws  FtpProtocolException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @throws  UnknownHostException if trying to connect to an unknown host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public synchronized void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Proxy p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (instProxy == null) { // no per connection proxy specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            /**
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   216
             * Do we have to use a proxy?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   218
            ProxySelector sel = java.security.AccessController.doPrivileged(
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   219
                    new java.security.PrivilegedAction<ProxySelector>() {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   220
                        public ProxySelector run() {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   221
                            return ProxySelector.getDefault();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   222
                        }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   223
                    });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (sel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                URI uri = sun.net.www.ParseUtil.toURI(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                Iterator<Proxy> it = sel.select(uri).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    p = it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    if (p == null || p == Proxy.NO_PROXY ||
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   230
                        p.type() == Proxy.Type.SOCKS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        break;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   232
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    if (p.type() != Proxy.Type.HTTP ||
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   234
                            !(p.address() instanceof InetSocketAddress)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                        sel.connectFailed(uri, p.address(), new IOException("Wrong proxy type"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    // OK, we have an http proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    InetSocketAddress paddr = (InetSocketAddress) p.address();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        http = new HttpURLConnection(url, p);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   242
                        http.setDoInput(getDoInput());
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   243
                        http.setDoOutput(getDoOutput());
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   244
                        if (connectTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            http.setConnectTimeout(connectTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   246
                        }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   247
                        if (readTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            http.setReadTimeout(readTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   249
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        http.connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        sel.connectFailed(uri, paddr, ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                        http = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        } else { // per connection proxy specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            p = instProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (p.type() == Proxy.Type.HTTP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                http = new HttpURLConnection(url, instProxy);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   263
                http.setDoInput(getDoInput());
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   264
                http.setDoOutput(getDoOutput());
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   265
                if (connectTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    http.setConnectTimeout(connectTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   267
                }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   268
                if (readTimeout >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    http.setReadTimeout(readTimeout);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   270
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                http.connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (user == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            user = "anonymous";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            String vers = java.security.AccessController.doPrivileged(
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   280
                    new GetPropertyAction("java.version"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            password = java.security.AccessController.doPrivileged(
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   282
                    new GetPropertyAction("ftp.protocol.user",
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   283
                                          "Java" + vers + "@"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        try {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   286
            ftp = FtpClient.create();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   287
            if (p != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   288
                ftp.setProxy(p);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   289
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            setTimeouts();
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   291
            if (port != -1) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   292
                ftp.connect(new InetSocketAddress(host, port));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   293
            } else {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   294
                ftp.connect(new InetSocketAddress(host, FtpClient.defaultPort()));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   295
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // Maybe do something smart here, like use a proxy like iftp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // Just keep throwing for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throw e;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   300
        } catch (FtpProtocolException fe) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   301
            throw new IOException(fe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        try {
25805
0bc2aa4aadbe 8031435: Ftp download does not work properly for ftp user without password
robm
parents: 7668
diff changeset
   304
            ftp.login(user, password == null ? null : password.toCharArray());
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   305
        } catch (sun.net.ftp.FtpProtocolException e) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   306
            ftp.close();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   307
            // Backward compatibility
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   308
            throw new sun.net.ftp.FtpLoginException("Invalid username/password");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Decodes the path as per the RFC-1738 specifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private void decodePath(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int i = path.indexOf(";type=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (i >= 0) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   320
            String s1 = path.substring(i + 6, path.length());
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   321
            if ("i".equalsIgnoreCase(s1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                type = BIN;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   323
            }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   324
            if ("a".equalsIgnoreCase(s1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                type = ASCII;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   326
            }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   327
            if ("d".equalsIgnoreCase(s1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                type = DIR;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   329
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            path = path.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (path != null && path.length() > 1 &&
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   333
                path.charAt(0) == '/') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            path = path.substring(1);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   335
        }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   336
        if (path == null || path.length() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            path = "./";
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   338
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (!path.endsWith("/")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            i = path.lastIndexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (i > 0) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   342
                filename = path.substring(i + 1, path.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                filename = ParseUtil.decode(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                pathname = path.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                filename = ParseUtil.decode(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                pathname = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            pathname = path.substring(0, path.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            filename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   353
        if (pathname != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            fullpath = pathname + "/" + (filename != null ? filename : "");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   355
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            fullpath = filename;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   357
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * As part of RFC-1738 it is specified that the path should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * interpreted as a series of FTP CWD commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * This is because, '/' is not necessarly the directory delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * on every systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   366
    private void cd(String path) throws FtpProtocolException, IOException {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   367
        if (path == null || path.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   369
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (path.indexOf('/') == -1) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   371
            ftp.changeDirectory(ParseUtil.decode(path));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   375
        StringTokenizer token = new StringTokenizer(path, "/");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   376
        while (token.hasMoreTokens()) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   377
            ftp.changeDirectory(ParseUtil.decode(token.nextToken()));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   378
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Get the InputStream to retreive the remote file. It will issue the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * "get" (or "dir") command to the ftp server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return  the <code>InputStream</code> to the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @throws  IOException if already opened for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @throws  FtpProtocolException if errors occur during the transfert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   390
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (!connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   396
        if (http != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            return http.getInputStream();
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   398
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   400
        if (os != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw new IOException("Already opened for output");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   402
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (is != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        MessageHeader msgh = new MessageHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   410
        boolean isAdir = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            decodePath(url.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (filename == null || type == DIR) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   414
                ftp.setAsciiType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                cd(pathname);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   416
                if (filename == null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   417
                    is = new FtpInputStream(ftp, ftp.list(null));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   418
                } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    is = new FtpInputStream(ftp, ftp.nameList(filename));
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   420
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } else {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   422
                if (type == ASCII) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   423
                    ftp.setAsciiType();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   424
                } else {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   425
                    ftp.setBinaryType();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   426
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                cd(pathname);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   428
                is = new FtpInputStream(ftp, ftp.getFileStream(filename));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            /* Try to get the size of the file in bytes.  If that is
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   432
            successful, then create a MeteredStream. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            try {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   434
                long l = ftp.getLastTransferSize();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   435
                msgh.add("content-length", Long.toString(l));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   436
                if (l > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   438
                    // Wrap input stream with MeteredStream to ensure read() will always return -1
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   439
                    // at expected length.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   441
                    // Check if URL should be metered
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   442
                    boolean meteredInput = ProgressMonitor.getDefault().shouldMeterInput(url, "GET");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   443
                    ProgressSource pi = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   445
                    if (meteredInput) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   446
                        pi = new ProgressSource(url, "GET", l);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   447
                        pi.beginTracking();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   448
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   450
                    is = new MeteredStream(is, pi, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                e.printStackTrace();
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   454
            /* do nothing, since all we were doing was trying to
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   455
            get the size in bytes of the file */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   458
            if (isAdir) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   459
                msgh.add("content-type", "text/plain");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   460
                msgh.add("access-type", "directory");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   461
            } else {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   462
                msgh.add("access-type", "file");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   463
                String ftype = guessContentTypeFromName(fullpath);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   464
                if (ftype == null && is.markSupported()) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   465
                    ftype = guessContentTypeFromStream(is);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   466
                }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   467
                if (ftype != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   468
                    msgh.add("content-type", ftype);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   469
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                cd(fullpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                /* if that worked, then make a directory listing
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   475
                and build an html stream with all the files in
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   476
                the directory */
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   477
                ftp.setAsciiType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   479
                is = new FtpInputStream(ftp, ftp.list(null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                msgh.add("content-type", "text/plain");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   481
                msgh.add("access-type", "directory");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                throw new FileNotFoundException(fullpath);
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   484
            } catch (FtpProtocolException ex2) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   485
                throw new FileNotFoundException(fullpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   487
        } catch (FtpProtocolException ftpe) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   488
            throw new IOException(ftpe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        setProperties(msgh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Get the OutputStream to store the remote file. It will issue the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * "put" command to the ftp server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return  the <code>OutputStream</code> to the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws  IOException if already opened for input or the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *          points to a directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @throws  FtpProtocolException if errors occur during the transfert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   504
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public OutputStream getOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (!connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   510
        if (http != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   511
            OutputStream out = http.getOutputStream();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   512
            // getInputStream() is neccessary to force a writeRequests()
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   513
            // on the http client.
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   514
            http.getInputStream();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   515
            return out;
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   516
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   518
        if (is != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            throw new IOException("Already opened for input");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   520
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (os != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return os;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        decodePath(url.getPath());
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   527
        if (filename == null || filename.length() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw new IOException("illegal filename for a PUT");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   529
        }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   530
        try {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   531
            if (pathname != null) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   532
                cd(pathname);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   533
            }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   534
            if (type == ASCII) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   535
                ftp.setAsciiType();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   536
            } else {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   537
                ftp.setBinaryType();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   538
            }
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   539
            os = new FtpOutputStream(ftp, ftp.putFileStream(filename, false));
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   540
        } catch (FtpProtocolException e) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   541
            throw new IOException(e);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   542
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return os;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    String guessContentTypeFromFilename(String fname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return guessContentTypeFromName(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Gets the <code>Permission</code> associated with the host & port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @return  The <code>Permission</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   555
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public Permission getPermission() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (permission == null) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   558
            int urlport = url.getPort();
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   559
            urlport = urlport < 0 ? FtpClient.defaultPort() : urlport;
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   560
            String urlhost = this.host + ":" + urlport;
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   561
            permission = new SocketPermission(urlhost, "connect");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Sets the general request property. If a property with the key already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * exists, overwrite its value with the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param   key     the keyword by which the request is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *                  (e.g., "<code>accept</code>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @param   value   the value associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @throws IllegalStateException if already connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @see #getRequestProperty(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   576
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public void setRequestProperty(String key, String value) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   578
        super.setRequestProperty(key, value);
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   579
        if ("type".equals(key)) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   580
            if ("i".equalsIgnoreCase(value)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                type = BIN;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   582
            } else if ("a".equalsIgnoreCase(value)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                type = ASCII;
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   584
            } else if ("d".equalsIgnoreCase(value)) {
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   585
                type = DIR;
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   586
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                throw new IllegalArgumentException(
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   588
                        "Value of '" + key +
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   589
                        "' request property was '" + value +
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   590
                        "' when it must be either 'i', 'a' or 'd'");
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   591
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Returns the value of the named general request property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @param key the keyword by which the request is known (e.g., "accept").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @return  the value of the named general request property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *           connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @throws IllegalStateException if already connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see #setRequestProperty(java.lang.String, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   605
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public String getRequestProperty(String key) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   607
        String value = super.getRequestProperty(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (value == null) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   610
            if ("type".equals(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                value = (type == ASCII ? "a" : type == DIR ? "d" : "i");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   612
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   618
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public void setConnectTimeout(int timeout) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   620
        if (timeout < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            throw new IllegalArgumentException("timeouts can't be negative");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   622
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        connectTimeout = timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   626
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public int getConnectTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return (connectTimeout < 0 ? 0 : connectTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   631
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    public void setReadTimeout(int timeout) {
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   633
        if (timeout < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            throw new IllegalArgumentException("timeouts can't be negative");
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   635
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        readTimeout = timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
4155
460e37d40f12 6893702: Overhaul of Ftp Client internal code
jccollet
parents: 715
diff changeset
   639
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    public int getReadTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return readTimeout < 0 ? 0 : readTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
}