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

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

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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class InputStreamConverters {
	public static final ValueConverter URL_TO_STREAM = new ValueConverter() {
		@Override
		public InputStream convert(Object value) throws IllegalArgumentException {
			if (value instanceof URL) {
				try {
					return ((URL)value).openStream();
				} catch (IOException e) {
					return null;
				}
			}
			return null;
		}
	};
	public static final ValueConverter URL = ConcatenatedConverter.concat(URLConverters.DEFAULT, URL_TO_STREAM);
	
	public static final ValueConverter FILE_TO_STREAM = new ValueConverter() {
		@Override
		public InputStream convert(Object value) throws IllegalArgumentException {
			if (value instanceof File) {
				try {
					return new FileInputStream((File)value);
				} catch (IOException e) {
					return null;
				}
			}
			return null;
		}
	};
	public static final ValueConverter FILE = ConcatenatedConverter.concat(FileConverters.DEFAULT, FILE_TO_STREAM);
	
	public static final ValueConverter DEFAULT = new CompositeValueConverter().add(URL).add(FILE);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy