package org.ahmadsoft.stream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.sql.Blob; /** * Holds miscellaneous utilities. * @author Amin Ahmad */ public final class Util { public static byte[] getBytes(Blob blob) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[512]; int x= -1; InputStream is; try { is = blob.getBinaryStream(); while (-1 != (x=is.read(b))) { baos.write(b,0,x); } baos.close(); return baos.toByteArray(); } catch (Exception e) { return new byte[0]; } } }