String stream = new BaseCode64().EncodeBase64(content);
System.out.println("content" +content.length);
effect += insertAttachmentInfo(conn,attNo,processId,filename,stream);
这里把读取的流以base64保存,使用了类BaseCode64()的方法EncodeBase64。
代码如下:
Java代码
package com.ving.xzfw.util;
import java.io.ByteArrayOutputStream;
public class BaseCode64 {
private String TableBase64;
private String FError;
public BaseCode64()
{
TableBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
FError = new String();
FError = "";
}
public String DecodeBase64(byte [] Value){
ByteArrayOutputStream o = new ByteArrayOutputStream();
byte d[] = new byte[4];
try
{
int count = 0;
byte x[] = Value;
do
{
if(count >= x.length)
{
break;
}
for(int n = 0; n <= 3; n++)
{
if(count >= x.length)
{
d[n] = 64;
} else
{
int y = TableBase64.indexOf(x[count]);
if(y < 0)
{
y = 65;
}
d[n] = (byte)y;
}
count++;
}
o.write((byte)(((d[0] & 0x3f) << 2) + ((d[1] & 0x30) >> 4)));
if(d[2] != 64)
{
o.write((byte)(((d[1] & 0xf) << 4) + ((d[2] & 0x3c) >> 2)));
if(d[3] != 64)
{
o.write((byte)(((d[2] & 3) << 6) + (d[3] & 0x3f)));
}
}
} while(true);
}
catch(StringIndexOutOfBoundsException e)
{
FError = String.valueOf(String.valueOf(FError)) + String.valueOf(String.valueOf(e.toString()));
System.out.println(e.toString());
}
return o.toString();
}
public String EncodeBase64(byte [] Value){
ByteArrayOutputStream o = new ByteArrayOutputStream();
byte d[] = new byte[4];
try
{
int count = 0;
for(byte x[] = Value; count < x.length;)
{
byte c = x[count];
count++;
d[0] = (byte)((c & 0xfc) >> 2);
d[1] = (byte)((c & 3) << 4);
if(count < x.length)
{
c = x[count];
count++;
d[1] = (byte)(d[1] + (byte)((c & 0xf0) >> 4));
d[2] = (byte)((c & 0xf) << 2);
if(count < x.length)
{
c = x[count];
count++;
d[2] = (byte)(d[2] + ((c & 0xc0) >> 6));
d[3] = (byte)(c & 0x3f);
} else
{
d[3] = 64;
}
} else
{
d[2] = 64;
d[3] = 64;
}
int n = 0;
while(n <= 3)
{
o.write(TableBase64.charAt(d[n]));
n++;
}
}
}
catch(StringIndexOutOfBoundsException e)
{
FError = String.valueOf(String.valueOf(FError)) + String.valueOf(String.valueOf(e.toString()));
System.out.println(e.toString());
}
return o.toString();
}
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|