?? oracleblobparseblh.java
字號:
package gov.gdlt.ssgly.taxcore.taxblh.gzda.service;
import oracle.sql.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.sqlmap.client.*;
import com.ibatis.sqlmap.engine.builder.xml.*;
import com.ibatis.common.resources.*;
import com.ibatis.dao.client.*;
import gov.gdlt.ssgly.taxcore.taxdao.gzda.persistence.*;
import gov.gdlt.ssgly.taxcore.taxdao.gzda.persistence.blob.*;
import gov.gdlt.ssgly.taxcore.taxdao.gzda.persistence.iface.*;
import gov.gdlt.ssgly.taxcore.taxdao.gzda.persistence.sqlmapdao.*;
import gov.gdlt.ssgly.taxcore.taxblh.gzda.service.xmlinterface.impl.*;
import gov.gdlt.ssgly.taxcore.taxblh.gzda.service.xmlinterface.*;
import gov.gdlt.ssgly.taxcore.taxevent.gzda.persistence.entity.*;
import gov.gdlt.ssgly.taxcore.comm.blh.BaseBizLogicHandler;
import gov.gdlt.ssgly.taxcore.comm.exception.TaxBaseBizException;
import gov.gdlt.ssgly.taxcore.comm.exception.TaxBaseSystemException;
import gov.gdlt.ssgly.taxcore.comm.event.ResponseEvent;
import gov.gdlt.ssgly.taxcore.comm.event.RequestEvent;
import gov.gdlt.ssgly.taxcore.comm.servicelocator.SqlMapLocator;
import java.sql.*;
import gov.gdlt.ssgly.taxcore.taxevent.gzda.persistence.entity.*;
import gov.gdlt.ssgly.taxcore.comm.servicelocator.JDBCLocator;
import java.util.jar.*;
import java.util.zip.*;
public class OracleBlobParseBLH extends BaseBizLogicHandler{
protected DaoManager daoManager;
protected IfiledetailDao ifile;
public OracleBlobParseBLH() {
daoManager = DaoConfig.getDaomanager();
ifile = (IfiledetailDao) daoManager.getDao(gov.gdlt.ssgly.taxcore.taxdao.gzda.persistence.iface.IfiledetailDao.class);
}
public int inserttfile(String name,GZDAfileDetailVO parameter){
return ifile.tfileInsert(name,parameter);
}
public List selectfile(String name,String parameter){
return ifile.tfileSelect(name,parameter) ;
}
public List selectfile(String name,Map parameter){
return ifile.tfileSelect(name,parameter) ;
}
private InputStream getFileBlob(String id){
Connection con=null;
InputStream ins=null;
InputStream insout=null;
java.sql.Blob blob =null;
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
ByteArrayOutputStream bytearrayn=new ByteArrayOutputStream();
DataInputStream dns=null;
boolean iszip=false;
try {
con = JDBCLocator.getInstance().getJDBCConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT filedoc FROM T_GZDA_FILEMANAGERDETAIL WHERE url='"+id+"'");
while(rs.next()) {
blob =rs.getBlob("filedoc");
}
ins = blob.getBinaryStream();
// sqlMap.commitTransaction();
} catch (SQLException ex) {
}finally{
try {
if(con!=null){
con.close();
}
} catch (SQLException se) { }
}
//將數據流寫入
int l=0;
byte[] a=new byte[1024];
try {
while ((l = ins.read(a)) != -1) {
bytearray.write(a, 0, l);
}
} catch (IOException ex1){}
finally{
if(ins!=null){
try {
ins.close();
bytearray.close();
} catch (IOException ex2) {
}
}
}
ByteArrayInputStream byteins=new ByteArrayInputStream(bytearray.toByteArray());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(byteins));
ZipEntry entry=null;
try {
entry = zis.getNextEntry();
} catch (IOException ex2) {
}
if (entry!= null) {
//System.out.println("entry name=" + entry.getName());
iszip=true;
dns=new DataInputStream(zis);
}
if(iszip){
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = dns.read(b)) != -1) {
bytearrayn.write(b, 0, len);
}
} catch (IOException ex1) {
}
finally {
try {
if(ins!=null){
ins.close();
}
if(dns!=null){zis.closeEntry();zis.close();dns.close();bytearrayn.close();}
}catch(IOException io){
}
}
insout=new ByteArrayInputStream(bytearrayn.toByteArray());
}else{
insout=new ByteArrayInputStream(bytearray.toByteArray());
}
return insout;
}
private oracle.sql.BLOB getFileB(String id){
//SqlMapClient sqlMap=null;
//sqlMap=SqlMapLocator.getInstance().getSqlMapClient();
Connection con=null;
OutputStream ous=null;
InputStream ins=null;
oracle.sql.BLOB blob =null;
try {
//sqlMap.startTransaction();
con =JDBCLocator.getInstance().getJDBCConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT filedoc FROM T_GZDA_FILEMANAGERDETAIL WHERE url='"+id+"' for update");
while(rs.next()) {
blob =(oracle.sql.BLOB)rs.getBlob("filedoc");
}
// sqlMap.commitTransaction();
} catch (SQLException ex) {
System.out.println(ex.toString());
}finally{
try {
//sqlMap.endTransaction();
if(con!=null){
con.close();
}
} catch (SQLException se) { }
}
return blob;
}
private int deleteblob(String url){
Connection con=null;
int ret=0;
try {
con =JDBCLocator.getInstance().getJDBCConnection();
Statement st = con.createStatement();
ret=st.executeUpdate("delete FROM T_GZDA_FILEMANAGERDETAIL WHERE url='"+url+"'");
ret+=1;
} catch (SQLException ex) {
} finally {
try{
if(con!=null){
con.close();
}
}catch(SQLException se) {
}
}
return ret;
}
public byte[] selectblob(String id){
int BUFFER=2048;
DataInputStream dns=null;
byte[] byteout=null;
int ret=0;
java.sql.Blob blob=null;
OutputStream outStream =null;
InputStream ins=null;
OutputStream fout =null;
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
ByteArrayOutputStream bytearrayn=new ByteArrayOutputStream();
Connection con=null;
boolean iszip=false;
try {
con =JDBCLocator.getInstance().getJDBCConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT url,filedoc FROM T_GZDA_FILEMANAGERDETAIL WHERE url='"+id+"'");
while(rs.next()) {
blob = rs.getBlob("filedoc");
}
ins = blob.getBinaryStream();
// ByteArrayInputStream byteins=new ByteArrayInputStream(byteous.toByteArray());
// ZipInputStream zis = new ZipInputStream(new BufferedInputStream(byteins));
// ZipEntry entry;
//
// entry = zis.getNextEntry();
// if (entry!= null) {
// System.out.println("entry name=" + entry.getName());
// dns=new DataInputStream(zis);
// }
// sqlMap.commitTransaction();
} catch (SQLException ex) {
}
//catch (IOException ie) {}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = ins.read(b)) != -1) {
bytearray.write(b, 0, len);
}
} catch (IOException ex1) {
}
finally {
try {
if(con!=null){
con.close();
}
if(ins!=null){
ins.close();
}
} catch (SQLException se) {
}catch(IOException io){
}
}
/**
GZDAfileDetailVO detail=null;
BLOB bl=null;
BLOB blob=null;
List list=null;
InputStream ins=null;
OutputStream out=null;
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
list=selectfile("selectfile",id);
if(list.size()>=1){
detail=(GZDAfileDetailVO)list.get(0);
blob=(BLOB)detail.getFiledoc();
try {
bl=(BLOB)blob;
ins = bl.getBinaryStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = ins.read(b)) != -1) {
bytearray.write(b, 0, len);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -