org.unix4j.convert.URLConverters Maven / Gradle / Ivy
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