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

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

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

public class OutputStreamConverters {
	public static final ValueConverter URL_TO_STREAM = new ValueConverter() {
		@Override
		public OutputStream convert(Object value) throws IllegalArgumentException {
			if (value instanceof URL) {
				try {
					return ((URL)value).openConnection().getOutputStream();
				} 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 OutputStream convert(Object value) throws IllegalArgumentException {
			if (value instanceof File) {
				try {
					return new FileOutputStream((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