001package org.unix4j.convert; 002 003import java.io.File; 004import java.net.URL; 005 006public class FileConverters { 007 public static final ValueConverter<File> URL_TO_FILE = new ValueConverter<File>() { 008 @Override 009 public File convert(Object value) throws IllegalArgumentException { 010 if (value instanceof URL) { 011 return new File(((URL)value).getFile()); 012 } 013 return null; 014 } 015 }; 016 public static final ValueConverter<File> URL = ConcatenatedConverter.concat(URLConverters.DEFAULT, URL_TO_FILE); 017 public static final ValueConverter<File> STRING = new ValueConverter<File>() { 018 @Override 019 public File convert(Object value) throws IllegalArgumentException { 020 if (value != null) { 021 return new File(value.toString()); 022 } 023 return null; 024 } 025 }; 026 public static final ValueConverter<File> DEFAULT = new CompositeValueConverter<File>().add(URL).add(STRING); 027}