?? oracleblobparseblh.java
字號:
con.close();
}
} catch (SQLException se) { }
}
return rei;
}
public int saveblob(String urlstring,ByteArrayOutputStream bs){
int rei=0;
int BUFFER = 2048;
/**
GZDAfileDetailVO detail=new GZDAfileDetailVO();
detail.setUrl(urlstring);
BLOB blob=null;
List list=null;
try {
blob = BLOB.empty_lob();
} catch (SQLException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
}
detail.setFiledoc(blob) ;
daoManager.startTransaction();
rei=inserttfile("insertfile",detail);
list=selectfile("selectfile",urlstring);
if(list.isEmpty()){
System.out.println("插入空BLOB出錯!");
}
GZDAfileDetailVO td=(GZDAfileDetailVO)list.get(0);
BLOB lob=(BLOB)td.getFiledoc();
OutputStream outStream=null;
try {
//System.out.println(td.getFiledoc());
outStream= lob.getBinaryOutputStream();
} catch (SQLException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
byte[] b;
int len = 0;
try {
b = new byte[lob.getBufferSize()];
//while ((len = in.read(b)) != -1) {
outStream.write(bs.toByteArray());
//lob.putBytes(1,b);
//}
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
catch (SQLException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
finally {
try {
if(outStream!=null){
outStream.flush();
outStream.close();
}
} catch (IOException io) {}
}
//detail.setUrl("2111");
//detail.setFiledoc(lob) ;
//rei=inserttfile("insertfile",detail);
daoManager.commitTransaction();
**/
Connection con=null;
weblogic.jdbc.vendor.oracle.OracleThinBlob blob=null;
OutputStream outStream=null;
//try {
// blob = BLOB.empty_lob();
//} catch (SQLException e1) {
// TODO 自動生成 catch 塊
// e1.printStackTrace();
//}
try {
con = JDBCLocator.getInstance().getJDBCConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
st.executeUpdate("insert into T_GZDA_FILEMANAGERDETAIL values('" + urlstring +
"',empty_blob())");
ResultSet rs = st.executeQuery(
"SELECT url, filedoc FROM T_GZDA_FILEMANAGERDETAIL WHERE url='" +
urlstring + "' for update");
while (rs.next()) {
blob = (weblogic.jdbc.vendor.oracle.OracleThinBlob)rs.getBlob("filedoc");
}
outStream = blob.getBinaryOutputStream();
ByteArrayOutputStream newbs=createZipStream(bs);
byte[] b;
int len = 0;
try {
b = new byte[blob.getBufferSize()];
//while ((len = dis.read(b)) != -1) {
outStream.write(newbs.toByteArray());
//outStream.write(b, 0, len);
//lob.putBytes(1,b);
//}
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
catch (SQLException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
finally {
try {
if(outStream!=null){
outStream.flush();
outStream.close();
newbs.close();
bs.close();
}
} catch (IOException io) {}
}
rei=1;
// sqlMap.commitTransaction();
} catch (SQLException ex) {
System.out.println(ex.toString());
}finally{
try {
if(con!=null){
con.commit();
con.close();
}
} catch (SQLException se) { }
}
return rei;
}
// 得到XML節點中的二進制數據
public ByteArrayOutputStream getBytetream(HttpServletRequest request, HttpServletResponse response){
Document document=null;
ByteArrayInputStream inStream=null;
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
//XmlGetter xmlGetter=new XmlGetter();
String xml=XmlGetter.getData(request,"gb2312");
//System.out.println("傳入的數據:"+xml);
StringReader SR = new StringReader(xml);
SAXBuilder builder = new SAXBuilder();
try{
document = builder.build(SR);
}catch(JDOMException je){
System.out.println(je.toString());
}
// Get the root element
Element root = document.getRootElement();
Element params=root.getChild("upData");
String files=params.getText();
try {
byte[] bytes = new sun.misc.BASE64Decoder().decodeBuffer(files);
inStream=new ByteArrayInputStream(bytes);
} catch (IOException ex) {
System.out.println(ex.toString());
}
byte[] b = new byte[1024];
int len = 0;
try {
while ((len = inStream.read(b)) != -1) {
bytearray.write(b,0,len);
}
//bytearray.close();
} catch (IOException ex1) {
System.out.println(ex1.toString());
}
return bytearray;
}
protected ResponseEvent validateData(RequestEvent req) throws
Exception {
return null;
}
protected ResponseEvent performTask(RequestEvent req) throws
TaxBaseBizException, TaxBaseSystemException {
GZDAfileReqEvent reqEvent=(GZDAfileReqEvent)req ;
String dealMethod = reqEvent.getDealMethod();
int result=0;
GZDAfileResEvent resEvent = new GZDAfileResEvent();
if("selectblob".equalsIgnoreCase(dealMethod)){
String url=reqEvent.getURL();
resEvent.setDocfile(this.selectblob(url));
}else if("saveblob".equalsIgnoreCase(dealMethod)){
ByteArrayOutputStream bstream=reqEvent.getBs();
String url=reqEvent.getURL();
result=this.deleteblob(url);
if(result>0){
result = this.saveblob(url, bstream);
if (result != 1) {
resEvent.setRepCode(
"error save bolb to t_gzda_filedetail.2");
}
}else{
resEvent.setRepCode(
"error save bolb to t_gzda_filedetail.1");
}
}else if("savneweblob".equalsIgnoreCase(dealMethod)){
ByteArrayOutputStream bstream=reqEvent.getBs();
String url=reqEvent.getURL();
result = this.saveblob(url, bstream);
if (result != 1) {
resEvent.setRepCode(
"error save bolb to t_gzda_filedetail.2");
}
}
return resEvent;
}
private ByteArrayOutputStream createZipStream(ByteArrayOutputStream stream){
ByteArrayOutputStream btyout=new ByteArrayOutputStream();
ZipOutputStream out = null;
out=new ZipOutputStream(new BufferedOutputStream(btyout));
out.setMethod(ZipOutputStream.DEFLATED);
try {
out.putNextEntry(new ZipEntry("zip"));
} catch (IOException ex1) {
}
try {
out.write(stream.toByteArray());
out.close();
btyout.close();
} catch (IOException ex2) {
}
return btyout;
}
private InputStream createZipStream(InputStream stream){
ByteArrayOutputStream btyout=new ByteArrayOutputStream();
ZipOutputStream out = null;
out=new ZipOutputStream(new BufferedOutputStream(btyout));
out.setMethod(ZipOutputStream.DEFLATED);
try {
out.putNextEntry(new ZipEntry("zip"));
} catch (IOException ex1) {
}
try {
int l=0;
byte[] b=new byte[1024];
while((l=stream.read(b))!= -1)
out.write(b,0,l);
} catch (IOException ex2) {
}finally{
try {
out.close();
btyout.close();
} catch (IOException ex) {
}
}
InputStream ins=new ByteArrayInputStream(btyout.toByteArray());
return ins;
}
public static void main(String[] args) {
FileOutputStream dest = null;
ZipOutputStream out = null;
ByteArrayOutputStream byteout=new ByteArrayOutputStream();
System.out.println("a:"+byteout.size());
try {
dest = new FileOutputStream("C:\\test\\989898989898989.zip");
} catch (FileNotFoundException ex) {
}
out=new ZipOutputStream(new BufferedOutputStream(byteout));
out.setMethod(ZipOutputStream.DEFLATED);
try {
out.putNextEntry(new ZipEntry("zip"));
} catch (IOException ex1) {
}
byte[] test={'a','b','c',};
try {
out.write(test);
out.close();
dest.close();
byteout.close();
} catch (IOException ex2) {
}
System.out.println("b:"+byteout.toString());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -