Hi,
I am facing OutOfMemory exception in Java, Kindly help me to resolve this issue, really appreciate your help
ERROR: java.lang.OutOfMemoryError: Java heap space
CODE:
public Blob getBlob(String databaseInstance, InputStream inputStream) throws SQLException, Exception
{
applog.info("Entering getBlob");
InputStream stream = null;
applog.info("inputStream : " + inputStream);
stream = inputStream;
applog.info("stream : " + stream);
byte[] tmp = new byte[50000000];
byte[] blobValue = null;
int sz, len = 0;
while ((sz = stream.read(tmp)) != -1) {
if (blobValue == null) {
len = sz;
blobValue = tmp;
} else {
byte[] narr;
int nlen;
nlen = len + sz;
narr = new byte[nlen];
System.arraycopy(blobValue, 0, narr, 0, len);
System.arraycopy(tmp, 0, narr, len, sz);
blobValue = narr;
len = nlen;
narr = null;
}
}
if(null != blobValue) {
if (len != blobValue.length) {
byte[] narr = new byte[len];
System.arraycopy(blobValue, 0, narr, 0, len);
blobValue = narr;
narr = null;
}
applog.info("blobValue len : " + blobValue.length + " toString : " + blobValue.toString());
}
Blob newBlob = null;
newBlob = oracle.sql.BLOB.createTemporary(globalMetaCon, true, oracle.sql.BLOB.DURATION_SESSION);
if (blobValue != null) {
try {
applog.info("newBlob Before: " + newBlob.toString() + " len : " + newBlob.length());
if (newBlob != null) {
((oracle.sql.BLOB) newBlob).putBytes(1, blobValue);
applog.info("inside put bytes : " + blobValue);
}
applog.info("newBlob After: " + newBlob.toString() + " len : " + newBlob.length());
} catch (SQLException e) {
applog.error("ComponentScheduleDAO | getblob | sql exception" + e);
} catch (Exception e) {
applog.error("ComponentScheduleDAO | getblob | general exception" + e);
} finally {
if(null != stream)
{
stream.close();
}
}
}
applog.info("Exiting getBlob in ComponentScheduleDAO");
tmp = null;
blobValue = null;
return newBlob;
}
Thanks in advance...