use of sun.misc.BASE64Encoder in project portal by ixinportal.
the class SaveServiceTest method getPDFBinary.
/**
* 将PDF转换成base64编码
* 1.使用BufferedInputStream和FileInputStream从File指定的文件中读取内容;
* 2.然后建立写入到ByteArrayOutputStream底层输出流对象的缓冲输出流BufferedOutputStream
* 3.底层输出流转换成字节数组,然后由BASE64Encoder的对象对流进行编码
*/
static byte[] getPDFBinary(File file) {
FileInputStream fin = null;
BufferedInputStream bin = null;
ByteArrayOutputStream baos = null;
BufferedOutputStream bout = null;
try {
// 建立读取文件的文件输出流
fin = new FileInputStream(file);
// 在文件输出流上安装节点流(更大效率读取)
bin = new BufferedInputStream(fin);
// 创建一个新的 byte 数组输出流,它具有指定大小的缓冲区容量
baos = new ByteArrayOutputStream();
// 创建一个新的缓冲输出流,以将数据写入指定的底层输出流
bout = new BufferedOutputStream(baos);
byte[] buffer = new byte[1024];
int len = bin.read(buffer);
while (len != -1) {
bout.write(buffer, 0, len);
len = bin.read(buffer);
}
// 刷新此输出流并强制写出所有缓冲的输出字节,必须这行代码,否则有可能有问题
bout.flush();
byte[] bytes = baos.toByteArray();
// return bytes;
// sun公司的API
String strpdf = new BASE64Encoder().encodeBuffer(bytes).trim();
return strpdf.getBytes("utf-8");
// return encoder.encodeBuffer(bytes).trim();
// apache公司的API
// return Base64.encodeBase64String(bytes);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
http: try {
fin.close();
bin.close();
// 关闭 ByteArrayOutputStream 无效。此类中的方法在关闭此流后仍可被调用,而不会产生任何 IOException
// baos.close();
bout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
http: return null;
}
use of sun.misc.BASE64Encoder in project portal by ixinportal.
the class ReceiptTest method test.
@Test
public void test() {
// 正式系统地址
String url = "https://www.fapiao.com:53087/fpt-dsqz/services/DZFPService";
// String appId = "0d94a610c6e9a4260201b003bd78bdf8981af7906e4da43b96435bfaee4a089f"; //appid
String appId = "2550ac3d539f7db6f859485af99e63de9882514145fbc2199d3f65f3bfece980";
// String url = "https://dev.fapiao.com:19443/fpt-dsqz-spbm/services/DZFPService"; //测试地址
// String appId = "6d29f136114544bcc73edcce960c430231183cc192c433e2b9ebcad56e8ceb08"; //appid
// 执行命令后,会生成该testclient.truststore
String ssl_store = getClass().getClassLoader().getResource("").getPath() + File.separator + "fapiao.truststore";
// 证书的存取密码,即执行命令时填写的密码
String ssl_pwd = "ixin21060921";
System.setProperty("javax.net.ssl.trustStore", ssl_store);
System.setProperty("javax.net.ssl.keyStorePassword", ssl_pwd);
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
try {
org.apache.axis.client.Service s = new org.apache.axis.client.Service();
Call call = (Call) s.createCall();
call.setTargetEndpointAddress(new URL(url));
call.setOperation("doService");
String content;
String xml;
String val;
Map<String, String> temp;
Long count = 0L;
// 循环开票数量
for (int i = 0; i < 0; i++) {
count++;
content = getContent(count);
log.error("[input0]{}", content);
xml = getCommonXml("DFXJ1001", new BASE64Encoder().encodeBuffer(content.getBytes("UTF-8")), appId);
log.error("[input1]{}", xml);
Object[] fn01 = { xml };
val = (String) call.invoke(fn01);
log.error("[output]{}", val);
temp = parseXml(val);
if (!temp.get("returnCode").equals("0000")) {
log.error("ERRORLOG电子发票 {}", "开票推送失败,错误:" + temp.get("returnMessage"));
}
temp = parseXml(new String(new BASE64Decoder().decodeBuffer(temp.get("content")), "UTF-8"));
log.error("pefurl=" + temp.get("PDF_URL"));
}
} catch (Exception e) {
log.error("ERRORLOG电子发票 {}", "开票推送失败,错误:" + e.toString());
e.printStackTrace();
}
}
use of sun.misc.BASE64Encoder in project trainning by fernandotomasio.
the class LDAPNetworkUserDAO method encrypt.
private String encrypt(final String plaintext) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage());
}
try {
md.update(plaintext.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage());
}
byte[] raw = md.digest();
String hash = (new BASE64Encoder()).encode(raw);
return hash;
}
use of sun.misc.BASE64Encoder in project carbon-business-process by wso2.
the class BPMNInstanceService method encodeToString.
/**
* Internally used method to encode a image to String
*
* @param image
* @param type
* @return encoded String
*/
private String encodeToString(BufferedImage image, String type) {
String imageString = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ImageIO.write(image, type, bos);
byte[] imageBytes = bos.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
imageString = encoder.encode(imageBytes);
} catch (IOException e) {
log.error("Could not write image data", e);
} finally {
try {
bos.close();
} catch (IOException e) {
log.error("Could not close the byte stream", e);
}
}
return imageString;
}
use of sun.misc.BASE64Encoder in project summer by foxsugar.
the class MD5Util method getMD5.
public static String getMD5(String s) {
MessageDigest md5 = null;
String newstr = null;
try {
md5 = MessageDigest.getInstance("MD5");
BASE64Encoder base64en = new BASE64Encoder();
newstr = base64en.encode(md5.digest(s.getBytes("utf-8")));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return newstr;
}
Aggregations