|
@@ -19,6 +19,8 @@ import p2.p2server.P2Server;
|
|
|
import p2.pao.PaoRemote;
|
|
import p2.pao.PaoRemote;
|
|
|
import p2.pao.PaoSetRemote;
|
|
import p2.pao.PaoSetRemote;
|
|
|
import p2.util.P2Exception;
|
|
import p2.util.P2Exception;
|
|
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -29,6 +31,8 @@ import java.lang.reflect.Constructor;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigInteger;
|
|
import java.math.BigInteger;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -1043,4 +1047,56 @@ public class WebClientRest {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Path("imagetobase64")
|
|
|
|
|
+ @GET
|
|
|
|
|
+ public void imagetobase64(@QueryParam("url") String imageurl,@QueryParam("filename") String filename,@Context HttpServletResponse response) throws IOException {
|
|
|
|
|
+ // 创建URL
|
|
|
|
|
+// response.setContentType("image/jpeg");
|
|
|
|
|
+ final ByteArrayOutputStream data = new ByteArrayOutputStream();
|
|
|
|
|
+ String strNetImageToBase64;
|
|
|
|
|
+ URL url = new URL(imageurl);
|
|
|
|
|
+ final byte[] by = new byte[1024];
|
|
|
|
|
+ // 创建链接
|
|
|
|
|
+ final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
|
|
+ conn.setRequestMethod("GET");
|
|
|
|
|
+ conn.setConnectTimeout(5000);
|
|
|
|
|
+
|
|
|
|
|
+ InputStream is = conn.getInputStream();
|
|
|
|
|
+ // 将内容读取内存中
|
|
|
|
|
+ int len = -1;
|
|
|
|
|
+ while ((len = is.read(by)) != -1) {
|
|
|
|
|
+ data.write(by, 0, len);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 对字节数组Base64编码
|
|
|
|
|
+ BASE64Encoder encoder = new BASE64Encoder();
|
|
|
|
|
+ strNetImageToBase64 = encoder.encode(data.toByteArray());
|
|
|
|
|
+ // 关闭流
|
|
|
|
|
+ is.close();
|
|
|
|
|
+
|
|
|
|
|
+ BASE64Decoder decoder = new BASE64Decoder();
|
|
|
|
|
+ // Base64解码
|
|
|
|
|
+ byte[] b = decoder.decodeBuffer(strNetImageToBase64);
|
|
|
|
|
+ for (int i = 0; i < b.length; ++i) {
|
|
|
|
|
+ if (b[i] < 0) {// 调整异常数据
|
|
|
|
|
+ b[i] += 256;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ ServletOutputStream out;
|
|
|
|
|
+ try {
|
|
|
|
|
+ //3.通过response获取ServletOutputStream对象(out)
|
|
|
|
|
+ out = response.getOutputStream();
|
|
|
|
|
+ out.write(b);
|
|
|
|
|
+ out.close();
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|