/* Creating java source code */
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "RetString" as import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.*;
import oracle.jdbc.*;
import oracle.jdbc2.*;
import oracle.sql.*;
import java.sql.*;
import java.util.*;
import java.math.*;
public class Oscar {
public static void writeImageFromIMG(String readFilePath, String voffSet, String vlength, String fileName, String writeFilePath) throws Exception {
try {
ByteArrayOutputStream ous = null;
InputStream ios = null;
int offSet =Integer.parseInt(voffSet);
int length =Integer.parseInt(vlength);
try {
File file = new File(readFilePath);
byte[] buffer = new byte[(int) file.length()];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(file);
int actualByteLengthForRead = 0;
while ((actualByteLengthForRead = ios.read(buffer)) != -1) {
ous.write(buffer, offSet, length);
}
} finally {
try {
if (ous != null) {
ous.close();
}
} catch (IOException e) {
}
try {
if (ios != null) {
ios.close();
}
} catch (IOException e) {
}
}
FileOutputStream fos = new FileOutputStream(writeFilePath + fileName + ".tif");
fos.write(ous.toByteArray());
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/************* Creating Oracle Procedure *********************/
CREATE OR REPLACE PROCEDURE MICR.DPR_EXTRACT_BUNDLE_IMAGE
(P_readFilePath IN VARCHAR2,
P_offSet IN VARCHAR2,
P_length IN VARCHAR2,
P_fileName IN VARCHAR2,
P_writeFilePath IN VARCHAR2
)
AS LANGUAGE JAVA
NAME 'Oscar.writeImageFromIMG(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)';
/
/************** Using This ************************/
begin
FOR i IN (SELECT '22479581_Front' data_no, '63197' lengthofimagedata,
'0' offsetofimagedata, 0 front_rear
FROM DUAL
UNION ALL
SELECT '22479581_Rear' data_no, '8541' lengthofimagedata,
'63197' offsetofimagedata, 1 front_rear
FROM DUAL) loop
DPR_EXTRACT_BUNDLE_IMAGE('/u01/XML/ICE/ICE-PBM-W210-R2386-D20130708-B260.img',i.offsetofimagedata,i.lengthofimagedata,i.data_no,'/u01/XML/ICE/');
end loop;
end;
/*********************************************************************/
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "RetString" as import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.*;
import oracle.jdbc.*;
import oracle.jdbc2.*;
import oracle.sql.*;
import java.sql.*;
import java.util.*;
import java.math.*;
public class Oscar {
public static void writeImageFromIMG(String readFilePath, String voffSet, String vlength, String fileName, String writeFilePath) throws Exception {
try {
ByteArrayOutputStream ous = null;
InputStream ios = null;
int offSet =Integer.parseInt(voffSet);
int length =Integer.parseInt(vlength);
try {
File file = new File(readFilePath);
byte[] buffer = new byte[(int) file.length()];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(file);
int actualByteLengthForRead = 0;
while ((actualByteLengthForRead = ios.read(buffer)) != -1) {
ous.write(buffer, offSet, length);
}
} finally {
try {
if (ous != null) {
ous.close();
}
} catch (IOException e) {
}
try {
if (ios != null) {
ios.close();
}
} catch (IOException e) {
}
}
FileOutputStream fos = new FileOutputStream(writeFilePath + fileName + ".tif");
fos.write(ous.toByteArray());
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/************* Creating Oracle Procedure *********************/
CREATE OR REPLACE PROCEDURE MICR.DPR_EXTRACT_BUNDLE_IMAGE
(P_readFilePath IN VARCHAR2,
P_offSet IN VARCHAR2,
P_length IN VARCHAR2,
P_fileName IN VARCHAR2,
P_writeFilePath IN VARCHAR2
)
AS LANGUAGE JAVA
NAME 'Oscar.writeImageFromIMG(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)';
/
/************** Using This ************************/
begin
FOR i IN (SELECT '22479581_Front' data_no, '63197' lengthofimagedata,
'0' offsetofimagedata, 0 front_rear
FROM DUAL
UNION ALL
SELECT '22479581_Rear' data_no, '8541' lengthofimagedata,
'63197' offsetofimagedata, 1 front_rear
FROM DUAL) loop
DPR_EXTRACT_BUNDLE_IMAGE('/u01/XML/ICE/ICE-PBM-W210-R2386-D20130708-B260.img',i.offsetofimagedata,i.lengthofimagedata,i.data_no,'/u01/XML/ICE/');
end loop;
end;
/*********************************************************************/