Skip to content

Commit 2725df2

Browse files
author
sanbo
committed
init version 4.0.8
1 parent 3d4f940 commit 2725df2

File tree

15 files changed

+1394
-0
lines changed

15 files changed

+1394
-0
lines changed

AnalysysJavasdk/pom.xml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>cn.com.analysys</groupId>
6+
<name>javasdk</name>
7+
<artifactId>javasdk</artifactId>
8+
<version>4.0.8</version>
9+
<packaging>jar</packaging>
10+
<description>Analysys Java SDK</description>
11+
<url>https://ark.analysys.cn</url>
12+
13+
<licenses>
14+
<license>
15+
<name>The GPL Software License, Version 3.0</name>
16+
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
17+
</license>
18+
</licenses>
19+
20+
<developers>
21+
<developer>
22+
<name>analysys</name>
23+
<email>analysys@analysys.com.cn</email>
24+
<url>https://ark.analysys.cn</url>
25+
</developer>
26+
</developers>
27+
28+
<scm>
29+
<connection>scm:git@github.com:analysys/argo-sdk-java.git</connection>
30+
<developerConnection>scm:git@github.com:analysys/argo-sdk-java.git</developerConnection>
31+
<url>git@github.com:analysys/argo-sdk-java.git</url>
32+
</scm>
33+
34+
<properties>
35+
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
36+
<project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.apache.httpcomponents</groupId>
42+
<artifactId>httpclient</artifactId>
43+
<version>4.5.5</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>com.fasterxml.jackson.core</groupId>
47+
<artifactId>jackson-databind</artifactId>
48+
<version>[2.9.8,)</version>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>3.7.0</version>
58+
<configuration>
59+
<source>1.7</source>
60+
<target>1.7</target>
61+
<encoding>UTF-8</encoding>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-source-plugin</artifactId>
66+
<version>3.0.1</version>
67+
<configuration>
68+
<attach>true</attach>
69+
</configuration>
70+
<executions>
71+
<execution>
72+
<phase>compile</phase>
73+
<goals>
74+
<goal>jar</goal>
75+
</goals>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
<plugin>
80+
<artifactId>maven-jar-plugin</artifactId>
81+
<version>3.0.2</version>
82+
</plugin>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-javadoc-plugin</artifactId>
86+
<version>3.0.0</version>
87+
<configuration>
88+
<aggregate>true</aggregate>
89+
<charset>UTF-8</charset>
90+
<encoding>UTF-8</encoding>
91+
<docencoding>UTF-8</docencoding>
92+
</configuration>
93+
<executions>
94+
<execution>
95+
<phase>package</phase>
96+
<goals>
97+
<goal>jar</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-gpg-plugin</artifactId>
105+
<version>1.6</version>
106+
<executions>
107+
<execution>
108+
<id>sign-artifacts</id>
109+
<phase>verify</phase>
110+
<goals>
111+
<goal>sign</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
<plugin>
117+
<artifactId>maven-assembly-plugin</artifactId>
118+
<configuration>
119+
<descriptorRefs>
120+
<descriptorRef>jar-with-dependencies</descriptorRef>
121+
</descriptorRefs>
122+
<archive>
123+
<manifest>
124+
<mainClass></mainClass>
125+
</manifest>
126+
</archive>
127+
</configuration>
128+
<executions>
129+
<execution>
130+
<id>make-assembly</id>
131+
<phase>package</phase>
132+
<goals>
133+
<goal>single</goal>
134+
</goals>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
</plugins>
139+
</build>
140+
</project>
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package cn.com.analysys.javasdk;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.UnsupportedEncodingException;
7+
import java.util.zip.GZIPInputStream;
8+
import java.util.zip.GZIPOutputStream;
9+
10+
/**
11+
* @author admin
12+
*/
13+
public class AnalysysEncoder {
14+
public static final String GZIP_ENCODE_UTF_8 = "UTF-8";
15+
16+
/**
17+
* 编码
18+
* @param str 待处理字符串
19+
* @return 字节数组
20+
*/
21+
public static byte[] compress(String str) {
22+
return compress(str, GZIP_ENCODE_UTF_8);
23+
}
24+
25+
/**
26+
* 解码
27+
* @param bytes 待处理字节
28+
* @return 解码后的字符串
29+
* @throws IOException IO异常
30+
*/
31+
public static String uncompress(byte[] bytes) throws IOException {
32+
return uncompress(bytes, GZIP_ENCODE_UTF_8);
33+
}
34+
35+
/**
36+
* 对字符按照指定编码格式进行编码
37+
* @param str 待处理字符串
38+
* @param encoding 编码格式
39+
* @return 编码后的字节数组
40+
*/
41+
public static byte[] compress(String str, String encoding) {
42+
if (str == null || str.length() == 0) {
43+
return null;
44+
}
45+
ByteArrayOutputStream out = new ByteArrayOutputStream();
46+
GZIPOutputStream gzip;
47+
try {
48+
gzip = new GZIPOutputStream(out);
49+
gzip.write(str.getBytes(encoding));
50+
gzip.close();
51+
} catch (IOException e) {
52+
e.printStackTrace();
53+
}
54+
return out.toByteArray();
55+
}
56+
57+
/**
58+
* 对字节按照指定编码格式进行解码
59+
* @param bytes 待处理字节码
60+
* @param encoding 编码格式
61+
* @return 解码后的字符串
62+
* @throws IOException IO异常
63+
*/
64+
public static String uncompress(byte[] bytes, String encoding) throws IOException {
65+
ByteArrayOutputStream out = new ByteArrayOutputStream();
66+
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
67+
GZIPInputStream ungzip = new GZIPInputStream(in);
68+
byte[] buffer = new byte[256];
69+
int n;
70+
while ((n = ungzip.read(buffer)) >= 0) {
71+
out.write(buffer, 0, n);
72+
}
73+
return out.toString(encoding);
74+
}
75+
76+
/**
77+
* Base64解码
78+
* @param base64str 待处理的Base64编码的字符串
79+
* @return 解码后的字符串
80+
*/
81+
public static String ozBase64ToStr(String base64str){
82+
String base64Codep;
83+
try {
84+
base64Codep = new String(AnalysysEncoder.decode(base64str));
85+
return base64Codep;
86+
} catch (UnsupportedEncodingException e) {
87+
e.printStackTrace();
88+
return null;
89+
}
90+
}
91+
92+
/**
93+
* Base64编码
94+
* @param str 待处理字符串
95+
* @return 编码后的字符串
96+
*/
97+
public static String ozStrToBase64(String str){
98+
String basestr = AnalysysEncoder.encode(str.getBytes());
99+
return basestr;
100+
}
101+
102+
private static char[] base64EncodeChars = new char[] {
103+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
104+
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
105+
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
106+
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
107+
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
108+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
109+
'w', 'x', 'y', 'z', '0', '1', '2', '3',
110+
'4', '5', '6', '7', '8', '9', '+', '/' };
111+
112+
private static byte[] base64DecodeChars = new byte[] {
113+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
114+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
115+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
116+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
117+
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
118+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
119+
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
120+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
121+
122+
public static String encode(byte[] data) {
123+
StringBuffer sb = new StringBuffer();
124+
int len = data.length;
125+
int i = 0;
126+
int b1, b2, b3;
127+
while (i < len) {
128+
b1 = data[i++] & 0xff;
129+
if (i == len)
130+
{
131+
sb.append(base64EncodeChars[b1 >>> 2]);
132+
sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
133+
sb.append("==");
134+
break;
135+
}
136+
b2 = data[i++] & 0xff;
137+
if (i == len)
138+
{
139+
sb.append(base64EncodeChars[b1 >>> 2]);
140+
sb.append(base64EncodeChars[((b1 & 0x03) << 4) | ((b2 & 0xf0) >>> 4)]);
141+
sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
142+
sb.append("=");
143+
break;
144+
}
145+
b3 = data[i++] & 0xff;
146+
sb.append(base64EncodeChars[b1 >>> 2]);
147+
sb.append(base64EncodeChars[((b1 & 0x03) << 4) | ((b2 & 0xf0) >>> 4)]);
148+
sb.append(base64EncodeChars[((b2 & 0x0f) << 2) | ((b3 & 0xc0) >>> 6)]);
149+
sb.append(base64EncodeChars[b3 & 0x3f]);
150+
}
151+
return sb.toString();
152+
}
153+
154+
public static byte[] decode(String str) throws UnsupportedEncodingException {
155+
StringBuffer sb = new StringBuffer();
156+
byte[] data = str.getBytes("US-ASCII");
157+
int len = data.length;
158+
int i = 0;
159+
int b1, b2, b3, b4;
160+
while (i < len) {
161+
do {
162+
b1 = base64DecodeChars[data[i++]];
163+
} while (i < len && b1 == -1);
164+
if (b1 == -1) {break;}
165+
do {
166+
b2 = base64DecodeChars[data[i++]];
167+
} while (i < len && b2 == -1);
168+
if (b2 == -1) {break;}
169+
sb.append((char)((b1 << 2) | ((b2 & 0x30) >>> 4)));
170+
do {
171+
b3 = data[i++];
172+
if (b3 == 61) {return sb.toString().getBytes("iso8859-1");}
173+
b3 = base64DecodeChars[b3];
174+
} while (i < len && b3 == -1);
175+
if (b3 == -1) {break;}
176+
sb.append((char)(((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));
177+
do {
178+
b4 = data[i++];
179+
if (b4 == 61) {return sb.toString().getBytes("iso8859-1");}
180+
b4 = base64DecodeChars[b4];
181+
} while (i < len && b4 == -1);
182+
if (b4 == -1) {break;}
183+
sb.append((char)(((b3 & 0x03) << 6) | b4));
184+
}
185+
return sb.toString().getBytes("iso8859-1");
186+
}
187+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.com.analysys.javasdk;
2+
3+
/**
4+
* @author admin
5+
*/
6+
public class AnalysysException extends Exception {
7+
8+
public AnalysysException(String message) {
9+
super(message);
10+
}
11+
12+
public AnalysysException(Throwable error) {
13+
super(error);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)