com.crabshue.commons.xml.schema.ProtocolUtils Maven / Gradle / Ivy
package com.crabshue.commons.xml.schema;
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
/**
* Utility class for protocol operations.
*/
@Slf4j
public class ProtocolUtils {
protected ProtocolUtils() {
}
/**
* Check whether a URL points to a remote resource or not. Remote means that it starts with http: or https:.
*
* @param url the URL
* @return {@code true} if remote resource; {@code false} otherwise
*/
public static boolean isResourceRemote(@NonNull final URL url) {
final boolean ret = StringUtils.startsWith(url.toString(), Protocol.HTTP.getPrefix())
|| StringUtils.startsWith(url.toString(), Protocol.HTTPS.getPrefix());
logger.debug("URL [{}] is remote ? [{}]", url, ret);
return ret;
}
/**
* Check whether a URL (String) points to a remote resource or not. Remote means that it starts with http: or https:.
*
* @param url the URL
* @return {@code true} if remote resource; {@code false} otherwise
*/
public static boolean isResourceRemote(@NonNull final String url) {
final boolean ret = StringUtils.startsWith(url, Protocol.HTTP.getPrefix())
|| StringUtils.startsWith(url, Protocol.HTTPS.getPrefix());
logger.debug("URL [{}] is remote ? [{}]", url, ret);
return ret;
}
}