Advertisement
gaepiaz

Untitled

Nov 7th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. private static Blob generateDecodedBlob(String encodedData, Connection connection) throws SQLException {
  2.         logCreatingBlob(encodedData.length());
  3.  
  4.         long start = System.currentTimeMillis();
  5.         Blob blob = connection.createBlob();
  6.        
  7.         Logger.info("decoding base64 bytes");
  8.         Base64 codec = new Base64();
  9.         byte[] decoded = codec.decode(encodedData.getBytes());
  10.         blob.setBytes(1, decoded);
  11.         Logger.info("decoded.");
  12.        
  13.         Logger.info("BLOB created in %d milliseconds", System.currentTimeMillis() - start);
  14.         return blob;
  15.     }
  16.  
  17. private static void logCreatingBlob(int size) {
  18.         BigDecimal bg = new BigDecimal(((float) size) / ((1024 * 1024)));
  19.         bg = bg.setScale(2, BigDecimal.ROUND_HALF_UP);
  20.         Logger.info("Creating BLOB of " + size + " Bytes " + bg.floatValue() + " MegaBytes");
  21.  
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement