/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs2.provider.ftp;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticationData;
import org.apache.commons.vfs2.provider.GenericFileName;
import org.apache.commons.vfs2.provider.URLFileName;
import org.apache.commons.vfs2.provider.sftp.SftpConstants;
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * FTP client wrapper class with FTP client creation logic.
 */
class FtpClientWrapper extends AbstractFtpClientWrapper {
    FtpClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions,
                     Integer defaultTimeout) throws FileSystemException {
        super(root, fileSystemOptions, defaultTimeout);
    }

    protected FTPClient createClient() throws FileSystemException {
        final GenericFileName rootName = getRoot();
        Map<String, String> mParams = null;
        if (rootName instanceof URLFileName) {
            mParams = getQueryParams((URLFileName) rootName);
        }
        UserAuthenticationData authData = null;
        try {
            authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(), FtpFileProvider.AUTHENTICATOR_TYPES);

            char[] username = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                                                             UserAuthenticatorUtils.toChar(rootName.getUserName()));

            char[] password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                                                             UserAuthenticatorUtils.toChar(rootName.getPassword()));

            if (mParams == null) {

                return FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), username, password,
                                                         rootName.getPath(), getFileSystemOptions());
            } else {

                return FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), username, password,
                                                         rootName.getPath(), getFileSystemOptions(),
                                                         mParams.get(SftpConstants.PROXY_SERVER),
                                                         mParams.get(SftpConstants.PROXY_PORT),
                                                         mParams.get(SftpConstants.PROXY_USERNAME),
                                                         mParams.get(SftpConstants.PROXY_PASSWORD),
                                                         mParams.get(SftpConstants.TIMEOUT),
                                                         mParams.get(SftpConstants.RETRY_COUNT));
            }
        } finally {
            UserAuthenticatorUtils.cleanup(authData);
        }
    }

    private Map<String, String> getQueryParams(URLFileName urlFileName) {
        Map<String, String> mQueryParams = new HashMap<>();
        String strQuery = urlFileName.getQueryString();
        if (strQuery != null && !strQuery.equals("")) {
            for (String strParam : strQuery.split("&")) {
                String[] arrParam = strParam.split("=");
                if (arrParam.length >= 2) {
                    mQueryParams.put(arrParam[0], arrParam[1]);
                }
            }
        }
        return mQueryParams;
    }
}

@@ -3,229 +3,96 @@
 %0A * 
-Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF
+Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc.
  lic
@@ -110,17 +110,17 @@
 file to 
-Y
+y
 ou under
@@ -139,16 +139,19 @@
 License,
+%0A *
  Version
@@ -154,19 +154,16 @@
 sion 2.0
-%0A *
  (the %22L
@@ -204,16 +204,19 @@
 e except
+%0A *
  in comp
@@ -226,19 +226,16 @@
 nce with
-%0A *
  the Lic
@@ -239,17 +239,19 @@
 License.
- 
+%0A *
  You may
@@ -288,18 +288,16 @@
 at%0A *%0A *
-  
     http
@@ -399,16 +399,19 @@
 writing,
+%0A *
  softwar
@@ -411,19 +411,16 @@
 software
-%0A *
  distrib
@@ -462,16 +462,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -480,19 +480,16 @@
 %22 BASIS,
-%0A *
  WITHOUT
@@ -520,16 +520,19 @@
 S OF ANY
+%0A *
  KIND, e
@@ -556,19 +556,16 @@
 implied.
-%0A *
  See the
@@ -580,16 +580,19 @@
  for the
+%0A *
  specifi
@@ -627,19 +627,16 @@
 ions and
-%0A *
  limitat
@@ -639,16 +639,19 @@
 itations
+%0A *
  under t
@@ -661,16 +661,20 @@
 License.
+1%0A *
 %0A */%0Apac

Correct the license header of a file