Java URI Value Check isLocalURI(URI uri)

Here you can find the source of isLocalURI(URI uri)

Description

is Local URI

License

Apache License

Declaration

public static boolean isLocalURI(URI uri) throws IOException 

Method Source Code


//package com.java2s;
/*/*  ww w. ja  v a 2s.  c o  m*/
*    Copyright 2013 University of Southern California
*
*  Licensed 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.
*/

import java.io.*;
import java.net.*;

public class Main {
    public static boolean isLocalURI(URI uri) throws IOException {
        if (uri == null || uri.isOpaque() || !uri.isAbsolute() || uri.getHost() == null) {
            throw new IllegalArgumentException();
        }

        InetAddress host = InetAddress.getByName(uri.getHost());
        return host.isLoopbackAddress() || host.isAnyLocalAddress()
                || NetworkInterface.getByInetAddress(host) != null;
    }
}

Related

  1. isLocal(final URI uri)
  2. isLocal(final URI uri)
  3. isLocalFile(URI uri)
  4. isLocalFile(URI uri)
  5. isLocalUri(String uriString)
  6. isModuleURI(URI uri)
  7. isNormalized(String uriName)
  8. isOnTrustedUriWhiteList(final URI uri)
  9. isOriginForm(URI uri)