Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed May 15, 2017
1 parent 7f2b450 commit ae8c021
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 231 deletions.
25 changes: 25 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
== Dew Common(Dew公共模块)

=== 功能

. Json与Java对象转换(JsonHelper)
. Java Bean操作(BeanHelper)
. Java Class扫描操作(ClassScanHelper)
. Shell脚本操作(ShellHelper)
. 加解密(EncryptHelper)
. 响应处理模型(Resp)
. 定时器(TimerHelper)
. 常用时间处理(TimeHelper)
. 主流文件MIME整理(MimeHelper)
. 通用拦截器栈(DewInterceptorProcessor)

=== 使用

[source,xml]
----
<parent>
<groupId>com.ecfront.dew</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</parent>
----
24 changes: 0 additions & 24 deletions README.md

This file was deleted.

18 changes: 6 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<name>Dew Common</name>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version>

<properties>
<java.version>1.8</java.version>
Expand All @@ -18,13 +18,12 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.compilerVersion>${java.version}</maven.compiler.compilerVersion>
<jackson.version>2.8.7</jackson.version>
<jackson.version>2.8.8.1</jackson.version>
<beanutils.version>1.9.3</beanutils.version>
<jbcrypt.version>0.3m</jbcrypt.version>
<slf4j.version>1.7.22</slf4j.version>
<logback.version>1.1.7</logback.version>
<log4j.version>1.7.21</log4j.version>
<throwing.version>1.3</throwing.version>
<jbcrypt.version>0.4</jbcrypt.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
<log4j.version>2.8.2</log4j.version>
<junit.version>4.12</junit.version>
</properties>

Expand All @@ -49,11 +48,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>pl.touk</groupId>
<artifactId>throwing-function</artifactId>
<version>${throwing.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/ecfront/dew/common/BeanHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ecfront.dew.common;

import org.apache.commons.beanutils.BeanUtilsBean;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -228,4 +230,93 @@ private static String packageMethodNameByField(Field field, boolean isSet) {
}
}

public static class NullAwareBeanUtilsBean extends BeanUtilsBean {
@Override
public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException {
if (null != value) {
super.copyProperty(bean, name, value);
}
}
}

public static class FieldInfo {

private String name;
private Class<?> type;
private Set<Annotation> annotations;
private Field field;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Class<?> getType() {
return type;
}

public void setType(Class<?> type) {
this.type = type;
}

public Set<Annotation> getAnnotations() {
return annotations;
}

public void setAnnotations(Set<Annotation> annotations) {
this.annotations = annotations;
}

public Field getField() {
return field;
}

public void setField(Field field) {
this.field = field;
}
}

public static class MethodInfo {

private String name;
private Class<?> returnType;
private Set<Annotation> annotations;
private Method method;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Class<?> getReturnType() {
return returnType;
}

public void setReturnType(Class<?> returnType) {
this.returnType = returnType;
}

public Set<Annotation> getAnnotations() {
return annotations;
}

public void setAnnotations(Set<Annotation> annotations) {
this.annotations = annotations;
}

public Method getMethod() {
return method;
}

public void setMethod(Method method) {
this.method = method;
}
}

}
4 changes: 3 additions & 1 deletion src/main/java/com/ecfront/dew/common/ClassScanHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.*;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/ecfront/dew/common/EncryptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
Expand Down Expand Up @@ -153,27 +155,49 @@ public static PublicKey getPublicKey(String key, String algorithm) throws NoSuch
*
* @param data 要加密的数据
* @param key 公钥或私钥文件
* @param keyLength 密钥长度
* @param algorithm 非对称算法,如 RSA
* @return 加密后的数据
*/
public static byte[] encrypt(byte[] data, Key key, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
public static byte[] encrypt(byte[] data, Key key, int keyLength, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(data);
return packageCipher(data, cipher, keyLength / 8 - 11, data.length);
}

/**
* 解密
*
* @param data 要解密的数据
* @param key 公钥或私钥文件
* @param keyLength 密钥长度
* @param algorithm 非对称算法,如 RSA
* @return 解密后的数据
*/
public static byte[] decrypt(byte[] data, Key key, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
public static byte[] decrypt(byte[] data, Key key, int keyLength, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(data);
return packageCipher(data, cipher, keyLength / 8, data.length);
}

private static byte[] packageCipher(byte[] data, Cipher cipher, int maxLength, int inputLength) throws IllegalBlockSizeException, BadPaddingException, IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
while (inputLength - offSet > 0) {
if (inputLength - offSet > maxLength) {
cache = cipher.doFinal(data, offSet, maxLength);
} else {
cache = cipher.doFinal(data, offSet, inputLength - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * maxLength;
}
byte[] decryptedData = out.toByteArray();
out.close();
return decryptedData;
}

/**
Expand Down
45 changes: 0 additions & 45 deletions src/main/java/com/ecfront/dew/common/FieldInfo.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/com/ecfront/dew/common/MethodInfo.java

This file was deleted.

Loading

0 comments on commit ae8c021

Please sign in to comment.