import java.sql.Blob; import javax.sql.rowset.serial.SerialBlob; byte[] byteArray = .....; Blob blob = new SerialBlob(byteArray);
public static SerialBlob JSONToBlob(JSONObject object) throws SQLException { String text = object.toString(); text = text == null ? "{}" : text; return new SerialBlob(text.getBytes()); } public static JSONObject blobToJSON(SerialBlob blob) throws SerialException, IOException, JSONException { InputStream result = blob.getBinaryStream(); String jsonString = new String(toByteArray(result)); return new JSONObject(jsonString); } private static byte[] toByteArray(InputStream result) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int i; while(( i = result.read())== -1) { out.write(i); } return out.toByteArray(); }
@Test public void testReferencePersistence() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialBlob blob = new SerialBlob(testString.getBytes()); BlobType bv = new BlobType(blob); bv.setReferenceStreamId(null); // now force to serialize BlobType read = UnitTestUtil.helpSerialize(bv); assertNull(read.getReferenceStreamId()); assertEquals(testString, new String(read.getBytes(1, (int)blob.length()))); }
/** * String 2 blob blob. * * @param str the str * @return the blob * @throws SQLException the sql exception */ public static Blob string2blob(String str) throws SQLException { if (str == null) { return null; } return new SerialBlob(str.getBytes()); }
@Override public Blob toDatabaseType(byte[] value) { if (value == null) { return null; } try { return new SerialBlob(value); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public Blob read(ResultSet results, int column) throws SQLException { byte[] value = results.getBytes(column); return results.wasNull() ? null : new SerialBlob(value); }
@Override public Blob toDatabaseType(BigInteger value) { if (value == null) return null; try { return new SerialBlob(value.toByteArray()); } catch (final SQLException ex) { throw new SpeedmentTypeMapperException( "Error mapping BigInteger to Blob.", ex); } }
/** * String 2 blob blob. * * @param str the str * @return the blob */ public static Blob string2blob(String str) { if (str == null) { return null; } try { return new SerialBlob(str.getBytes()); } catch (Exception e) { throw new ShouldNeverHappenException(e); } }
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);
@Override protected Blob getBlob(ResultSet resultSet, int columnIndex, Metadata m) throws SQLException { byte[] bytes = resultSet.getBytes(columnIndex); if (!resultSet.wasNull()) { return new SerialBlob(bytes); } return null; } }
/** * Bulk constructor. */ public Blob(final byte[] bytes) throws SQLException { this.underlying = new SerialBlob(bytes); } // end of <init>
/** * Returns a BLOB with given |data|. * * @param data the binary data * @return the created BLOB * @throws SQLException if fails to create a BLOB */ public Blob createBlob(final byte[] data) throws SQLException { return new javax.sql.rowset.serial.SerialBlob(data); } // end of createBlob
@Override public Blob createSerial(Blob blob) throws SQLException { return new SerialBlob(blob); } }
@POST @Path("/documents") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response loanDocuments(@FormDataParam("file") byte[] uploadedByteArray, @FormDataParam("file") FormDataContentDisposition detail) throws SQLException { java.sql.Blob blob = new javax.sql.rowset.serial.SerialBlob(uploadedByteArray); return Response.status(200).entity("FILE UPLOAD SUCCESS").build(); }
byte[] buff = bos.toByteArray(); Blob drawingBlob = null; drawingBlob = new SerialBlob(buff); drawing.setDrawingObject(drawingBlob);
for(int x = 0; x < byteFiles.size(); x++){ fileBlobs.add(new javax.sql.rowset.serial.SerialBlob(byteFiles.get(x))); }
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);
@Override protected Blob valueToDBType(String value) throws SQLException { if (value != null) { return new SerialBlob(value.getBytes(StandardCharsets.UTF_8)); } else { return null; } }