1 8 9 package org.enhydra.oyster.util; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import java.io.File ; 13 import java.io.FileInputStream ; 14 import java.io.InputStream ; 15 import java.io.IOException ; 16 17 22 public class ConvertAssist { 23 24 30 public static String inStreamToString(InputStream in0) throws SMIMEException { 31 32 String sAtach = new String (); 33 try { 34 byte[] b = new byte[100000]; 35 int a = in0.read(b); 36 while (a == 100000) { 37 sAtach = sAtach.concat(new String (b, "ISO-8859-1")); 38 a = in0.read(b); 39 } 40 in0.close(); 41 sAtach = sAtach.concat(new String (b, "ISO-8859-1").substring(0, a)); 42 } 43 catch(IOException e) { 44 throw SMIMEException.getInstance("org.enhydra.oyster.util.ConvertAssist", 45 e, "inStreamToString"); 46 } 47 return sAtach; 48 } 49 50 51 57 public static byte[] inStreamToByteArray(InputStream in0) throws SMIMEException { 58 59 byte[] returnArray = null; 60 try { 61 returnArray = ConvertAssist.inStreamToString(in0).getBytes("ISO-8859-1"); 62 } 63 catch(IOException e) { 64 throw SMIMEException.getInstance("org.enhydra.oyster.util.ConvertAssist", 65 e, "inStreamToByteArray"); 66 } 67 68 return returnArray; 69 } 70 71 77 public static String fileToString(File file0) throws SMIMEException{ 78 79 String s = null; 80 try { 81 FileInputStream temp = new FileInputStream (file0); 82 s = new String (); 83 byte[] b = new byte[100000]; 84 int a = temp.read(b); 85 while (a == 100000) { 86 s = s.concat(new String (b, "ISO-8859-1")); 87 a = temp.read(b); 88 } 89 temp.close(); 90 s = s.concat(new String (b, "ISO-8859-1").substring(0, a)); 91 } 92 catch(Exception e) { 93 throw SMIMEException.getInstance("org.enhydra.oyster.util.FileAssist", 94 e, "fileToString"); 95 } 96 return s; 97 } 98 99 100 106 public static byte[] fileToByteArray(File file0) throws SMIMEException { 107 108 try { 109 return fileToString(file0).getBytes("ISO-8859-1"); 110 } 111 catch(Exception e) { 112 throw SMIMEException.getInstance("org.enhydra.oyster.util.FileAssist", 113 e, "fileToByteArray"); 114 } 115 } 116 117 } | Popular Tags |