Subversion Repositories Integrator Subversion

Rev

Rev 106 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.ec.domain.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import br.com.ec.core.util.VerificadorUtil;

public class ConversorUtil {

        public static <T> List<T> converterCollectionParaList(Collection<T> collection) {
                return VerificadorUtil.naoEstaNulo(collection)? new ArrayList<T>(collection) : new ArrayList<T>();
        }
       
        public static <T> Set<T> converterCollectionParaSet(Collection<T> collection) {
                return VerificadorUtil.naoEstaNulo(collection)? new HashSet<T>(collection) : new HashSet<T>();
        }
       
        public static byte[] converterFileParaBytes(File file) {
        FileInputStream fs;
                try {
                        fs = new FileInputStream(file);
                        byte[] byt = new byte[(int)file.length()];
                        for(int i = 0;i < file.length();i++){
                                byt[i] = (byte) fs.read();
                        }
                        return byt;
                } catch (FileNotFoundException e) {
                        throw new RuntimeException("Erro ao converter o arquivo.");
                } catch (IOException e) {
                        throw new RuntimeException("Erro ao converter o arquivo.");
                }
        }
}