1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.luni.internal.net.www.protocol.ftp;
19
20import java.io.IOException;
21import java.net.Proxy;
22import java.net.URL;
23import java.net.URLConnection;
24import java.net.URLStreamHandler;
25
26import org.apache.harmony.luni.util.Msg;
27
28public class Handler extends URLStreamHandler {
29    /**
30     * Open a URLConnection on the given URL.
31     */
32    @Override
33    protected URLConnection openConnection(URL u) throws IOException {
34        return new FtpURLConnection(u);
35    }
36
37    /**
38     * Returns a connection, which is established via the <code>proxy</code>,
39     * to the FTP server specified by this <code>URL</code>. If
40     * <code>proxy</code> is DIRECT type, the connection is made in normal
41     * way.
42     *
43     * @param u
44     *            the URL which the connection is pointing to
45     * @param proxy
46     *            the proxy which is used to make the connection
47     * @return a connection to the resource pointed by this url.
48     *
49     * @throws IOException
50     *             if this handler fails to establish a connection.
51     * @throws IllegalArgumentException
52     *             if any argument is null or the type of proxy is wrong.
53     * @throws UnsupportedOperationException
54     *             if the protocol handler doesn't support this method.
55     */
56    @Override
57    protected URLConnection openConnection(URL u, Proxy proxy)
58            throws IOException {
59        if (null == u || null == proxy) {
60            throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
61        }
62        return new FtpURLConnection(u, proxy);
63    }
64
65    /**
66     * Return the default port.
67     */
68    @Override
69    protected int getDefaultPort() {
70        return 21;
71    }
72}
73