Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.util; |
| 2 | |||
| 3 | import java.io.File; |
||
| 4 | import java.io.FileInputStream; |
||
| 5 | import java.io.FileNotFoundException; |
||
| 6 | import java.io.IOException; |
||
| 7 | import java.util.ArrayList; |
||
| 8 | import java.util.Collection; |
||
| 9 | import java.util.HashSet; |
||
| 10 | import java.util.List; |
||
| 11 | import java.util.Set; |
||
| 12 | |||
| 13 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 14 | |||
| 15 | public class ConversorUtil { |
||
| 16 | |||
| 17 | public static <T> List<T> converterCollectionParaList(Collection<T> collection) { |
||
| 18 | return VerificadorUtil.naoEstaNulo(collection)? new ArrayList<T>(collection) : new ArrayList<T>(); |
||
| 19 | } |
||
| 20 | |||
| 21 | public static <T> Set<T> converterCollectionParaSet(Collection<T> collection) { |
||
| 22 | return VerificadorUtil.naoEstaNulo(collection)? new HashSet<T>(collection) : new HashSet<T>(); |
||
| 23 | } |
||
| 24 | |||
| 25 | public static byte[] converterFileParaBytes(File file) { |
||
| 26 | FileInputStream fs; |
||
| 27 | try { |
||
| 28 | fs = new FileInputStream(file); |
||
| 29 | byte[] byt = new byte[(int)file.length()]; |
||
| 30 | for(int i = 0;i < file.length();i++){ |
||
| 31 | byt[i] = (byte) fs.read(); |
||
| 32 | } |
||
| 33 | return byt; |
||
| 34 | } catch (FileNotFoundException e) { |
||
| 35 | throw new RuntimeException("Erro ao converter o arquivo."); |
||
| 36 | } catch (IOException e) { |
||
| 37 | throw new RuntimeException("Erro ao converter o arquivo."); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |