Java Utililty Methods SQL Blob

List of utility methods to do SQL Blob

  1. HOME
  2. Java
  3. S
  4. SQL Blob

Description

The list of methods to do SQL Blob are organized into topic(s).

Method

float[] blob2FloatArray(Blob blob)
Convert a blob that we wrote a float array back into a usable array
float[] ret = null;
try {
 int blen = (int) blob.length();
 int nbytes = Float.SIZE / 8;
 int olen = (int) (blen / nbytes);
 ret = new float[olen];
 DataInputStream dis = new DataInputStream(blob.getBinaryStream());
 for (int o = 0; o < olen; o++) {
...
byte[] blobToBytes(Blob blob)
blob to byte array
byte[] bytes = null;
if (blob == null)
 return bytes;
try {
 bytes = blob.getBytes(1, (int) blob.length());
} catch (SQLException e) {
 e.printStackTrace();
return bytes;
byte[] blobToBytes(Blob blob)
blob To Bytes
BufferedInputStream is = null;
try {
 is = new BufferedInputStream(blob.getBinaryStream());
 byte[] bytes = new byte[(int) blob.length()];
 int len = bytes.length;
 int offset = 0;
 int read = 0;
 while (offset < len && (read = is.read(bytes, offset, len - offset)) >= 0) {
...
String getAsString(Blob blob)
get As String
BufferedReader br = new BufferedReader(new InputStreamReader(blob.getBinaryStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
 sb.append(line);
return sb.toString();
String getBlobType(byte[] image)
get Blob Type
if (isJPEGImage(image)) {
 return "jpg";
} else if (isPNGImage(image)) {
 return "png";
} else if (isGIFImage(image)) {
 return "gif";
return "png";
...
byte[] getDataFromBlob(Blob b)
get Data From Blob
ByteArrayOutputStream bout = new ByteArrayOutputStream();
InputStream in = b.getBinaryStream();
byte[] buffer = new byte[10240];
int len = 0;
while ((len = in.read(buffer, 0, 10240)) != -1) {
 bout.write(buffer, 0, len);
bout.flush();
...
byte[] getDataFromBlob(Blob b)
get Data From Blob
ByteArrayOutputStream bout = new ByteArrayOutputStream();
InputStream in = b.getBinaryStream();
byte[] buffer = new byte[10240];
int len = 0;
while ((len = in.read(buffer, 0, 10240)) != -1) {
 bout.write(buffer, 0, len);
return bout.toByteArray();
...
String getLongBlobTypeString(Connection conn)
get Long Blob Type String
if (isOracleServer(conn))
 return "BLOB";
return "LONGBLOB";
String getString(Blob blob)
get String
BufferedReader br = new BufferedReader(new InputStreamReader(blob.getBinaryStream(), "utf-8"));
String s = null;
StringBuilder sb = new StringBuilder();
while ((s = br.readLine()) != null) {
 sb.append(s);
return sb.toString();
String getStringValue(Blob blob)
Return a string representation of an object
String s = null;
InputStream is = null;
if (blob != null) {
 is = blob.getBinaryStream();
if (is != null) {
 BufferedInputStream bis = new BufferedInputStream(is, 4096);
 StringBuffer sb = new StringBuffer();
...


AltStyle によって変換されたページ (->オリジナル) /