All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unix4j.convert.URLConverters Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.convert;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class URLConverters {
	public static final ValueConverter URI = new ValueConverter() {
		@Override
		public URL convert(Object value) throws IllegalArgumentException {
			if (value instanceof URI) {
				try {
					return ((URI)value).toURL();
				} catch (Exception E) {
					return null;
				}
			}
			return null;
		}
	};
	public static final ValueConverter STRING = new ValueConverter() {
		@Override
		public URL convert(Object value) throws IllegalArgumentException {
			if (value != null) {
				try {
					return new URL(value.toString());
				} catch (MalformedURLException e) {
					return null;
				}
			}
			return null;
		}
	};
	public static final ValueConverter DEFAULT = new CompositeValueConverter().add(URI).add(STRING);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy