1package org.ahmadsoft.stream; 2 3import java.io.ByteArrayOutputStream; 4import java.io.InputStream; 5import java.sql.Blob; 6 7/** 8 * Holds miscellaneous utilities. 9 * @author Amin Ahmad 10 */ 11public final class Util { 12 public static byte[] getBytes(Blob blob) { 13 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 14 byte[] b = new byte[512]; 15 int x= -1; 16 InputStream is; 17 try { 18 is = blob.getBinaryStream(); 19 while (-1 != (x=is.read(b))) { 20 baos.write(b,0,x); 21 } 22 baos.close(); 23 return baos.toByteArray(); 24 } catch (Exception e) { 25 return new byte[0]; 26 } 27 } 28} 29