List of utility methods to do SQL Blob
boolean | isBlob(Object object) is Blob return object instanceof Blob; |
byte[] | readBlob(Blob blob) read Blob try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copy(new BufferedInputStream(blob.getBinaryStream()), baos); return baos.toByteArray(); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); |
byte[] | readBytes(Blob blob, byte[] defaultValue) read Bytes if (blob == null) { return defaultValue; InputStream is = null; try { int length = (int) blob.length(); if (length == 0) { return defaultValue; ... |
void | safeFree(Blob blob) Safely free a blob. if (blob != null) { try { blob.free(); } catch (Exception ignore) { |
void | safeFree(Blob blob) safe Free if (blob != null) { try { blob.free(); } catch (Exception ignore) { catch (AbstractMethodError ignore) { |
byte[] | toByteArray(Blob blob) to Byte Array try { return blob.getBytes(1, (int) blob.length()); } catch (SQLException e) { throw new RuntimeException("Error on transforming blob into array.", e); |
void | writeStringToBlob(String value, PreparedStatement preparedStatement, int index) write String To Blob try { final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); preparedStatement.setBinaryStream(index, new ByteArrayInputStream(bytes), bytes.length); } catch (SQLException e) { throw new RuntimeException(e); |
void | writeToBlob(int index, PreparedStatement ps, byte[] data) write To Blob ByteArrayInputStream bais = null; if (data != null) { bais = new ByteArrayInputStream(data); ps.setBinaryStream(index, bais); |