I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the code to read a blob from DB I am not having any luck, I am running this java programs using JDEVELOPER. Can anyone please give me some help?
The code is as follows:
The output from ReadFileIntoByt eArray is as follows:
---------
The result of ReadBlobIntoByt eArray is as follows:
58354F215025404 1505B345C505A58 353428505E29374 34329377D244549 4341522D5354414 E444152442D414E 544956495255532 D544553542D4649 4C452124482B482 A
The result I am getting is in hex, instead of in bytes. Please any advice is appreciated.
rgds,
sumak
The code is as follows:
Code:
...
private static byte[] getBytesFromBlob(Blob blob) throws Exception {
InputStream is = blob.getBinaryStream();
System.out.println("\nDEBUG: BlobInputStream is " );
// Get the size of the blob
int length = -1;
int size = (int)blob.length();
System.out.println("DEBUG: Length of blob" + " is " + size + "\n");
/*
* You cannot create an array using a long type. It needs to be an int
* type. Before converting to an int type, check to ensure that file is
* not loarger than Integer.MAX_VALUE;
*/
if (length > Integer.MAX_VALUE) {
System.out.println("File is too large to process");
return null;
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)size];
// Read in the bytes
int offset = 0;
int numRead = 0;
while ( (offset < bytes.length)
&&
( (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) ) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new Exception("Could not completely read file " );
}
is.close();
return bytes;
}
...
Code:
DEBUG: FileInputStream is c:\eicar.com DEBUG: Length of c:\eicar.com is 68 fileArray[0] = 88 : HEX=(0x58) : charValue=(X) fileArray[1] = 53 : HEX=(0x35) : charValue=(5) fileArray[2] = 79 : HEX=(0x4f) : charValue=(O) fileArray[3] = 33 : HEX=(0x21) : charValue=(!) ... fileArray[66] = 72 : HEX=(0x48) : charValue=(H) fileArray[67] = 42 : HEX=(0x2a) : charValue=(*)
The result of ReadBlobIntoByt eArray is as follows:
58354F215025404 1505B345C505A58 353428505E29374 34329377D244549 4341522D5354414 E444152442D414E 544956495255532 D544553542D4649 4C452124482B482 A
The result I am getting is in hex, instead of in bytes. Please any advice is appreciated.
rgds,
sumak
Comment