Java URI to Password getPassword(final URI uri)

Here you can find the source of getPassword(final URI uri)

Description

Method getPassword

License

Open Source License

Parameter

Parameter Description
uri a parameter

Return

TODO Complete Documentation

Declaration

public static String getPassword(final URI uri) 

Method Source Code

//package com.java2s;
/*// ww w  .j  av  a  2  s. co m
 * Copyright (c) 2014 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial concept and initial implementation
 */

import java.net.URI;

public class Main {
    /**
     * Method getPassword
     *
     * @param uri
     *
     * @return TODO Complete Documentation
     */
    public static String getPassword(final URI uri) {
        String retval = null;

        if (uri != null) {
            final String userInfo = uri.getUserInfo();

            if ((userInfo != null) && (userInfo.length() > 0)) {
                if (userInfo.indexOf(':') > -1) {
                    retval = userInfo.substring(userInfo.indexOf(':') + 1);
                }

                if ((retval != null) && (retval.length() > 0)) {
                    return retval;
                }
            }
        }

        return retval;
    }
}

Related

  1. getPassword(URI uri)
  2. getPasswordFromUserInfo(URI uri)