parent
cb672719a0
commit
697291236f
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1 @@
|
||||
/target/
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>tamguo-common</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
@ -0,0 +1,29 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.tamguo</groupId>
|
||||
<artifactId>tamguo-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>tamguo-modules-core</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,114 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.io.InterruptedIOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public abstract class AbstractRunningLogHandler implements LogHandler {
|
||||
|
||||
private static Method getStackTraceMethod;
|
||||
private static Method getClassNameMethod;
|
||||
private static Method getMethodNameMethod;
|
||||
private static Method getFileNameMethod;
|
||||
private static Method getLineNumberMethod;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?>[] noArgs = null;
|
||||
getStackTraceMethod = Throwable.class.getMethod("getStackTrace", noArgs);
|
||||
Class<?> stackTraceElementClass = Class.forName("java.lang.StackTraceElement");
|
||||
getClassNameMethod = stackTraceElementClass.getMethod("getClassName", noArgs);
|
||||
getMethodNameMethod = stackTraceElementClass.getMethod("getMethodName", noArgs);
|
||||
getFileNameMethod = stackTraceElementClass.getMethod("getFileName", noArgs);
|
||||
getLineNumberMethod = stackTraceElementClass.getMethod("getLineNumber", noArgs);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
LogDebug.debug("will use pre-JDK 1.4 methods to determine location.");
|
||||
} catch (NoSuchMethodException ex) {
|
||||
LogDebug.debug("will use pre-JDK 1.4 methods to determine location.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定class的StackTraceElement
|
||||
*
|
||||
* @param t
|
||||
* @param fqnOfCallingClass
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected StackTraceElement getRunningStackTrace(Throwable t, String fqnOfCallingClass) {
|
||||
if (getLineNumberMethod != null) {
|
||||
try {
|
||||
Object[] noArgs = null;
|
||||
Object[] elements = (Object[]) getStackTraceMethod.invoke(t, noArgs);
|
||||
for (int i = elements.length - 1; i >= 0; i--) {
|
||||
String thisClass = (String) getClassNameMethod.invoke(elements[i], noArgs);
|
||||
if (fqnOfCallingClass.equals(thisClass)) {
|
||||
// 执行class名称
|
||||
String className = fqnOfCallingClass;
|
||||
// 执行方法名称
|
||||
String methodName = (String) getMethodNameMethod.invoke(elements[i], noArgs);
|
||||
// 执行class文件名称
|
||||
String fileName = (String) getFileNameMethod.invoke(elements[i], noArgs);
|
||||
// 执行到行号
|
||||
int lineNumber = ((Integer) getLineNumberMethod.invoke(elements[i], noArgs)).intValue();
|
||||
return new StackTraceElement(className, methodName, fileName, lineNumber);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
LogDebug.debug("failed using JDK 1.4 methods", ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
if (ex.getTargetException() instanceof InterruptedException
|
||||
|| ex.getTargetException() instanceof InterruptedIOException) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
LogDebug.debug("failed using JDK 1.4 methods", ex);
|
||||
} catch (RuntimeException ex) {
|
||||
LogDebug.debug("failed using JDK 1.4 methods", ex);
|
||||
}
|
||||
}
|
||||
return this.createDefaultStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认StackTraceElement
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private StackTraceElement createDefaultStackTrace() {
|
||||
return new StackTraceElement(this.getClass().getName(), "log", this.getClass().getName(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String msg, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public class CException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 6401592364022805815L;
|
||||
|
||||
public CException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
/**
|
||||
* 统一异常处理 日志处理
|
||||
*
|
||||
*/
|
||||
public class ExceptionSupport {
|
||||
|
||||
private final static Result failResult = Result.failResult("500");
|
||||
private static LogHandler handler = new Log4jHandler();
|
||||
|
||||
private final static String LOG_INFO_PREFIX = "--info>> ";
|
||||
private final static String LOG_ERROR_PREFIX = "--error>> ";
|
||||
|
||||
public static Result resolverResult(String methodInfo, Class<?> clazz, Exception e) {
|
||||
if(e instanceof CException) {
|
||||
handler.info(formatInfoLevelMsg(methodInfo, e.getMessage()), clazz.getName());
|
||||
return Result.failResult(e.getMessage());
|
||||
}
|
||||
handler.error(formatErrorLevelMsg(methodInfo), e, clazz.getName());
|
||||
return failResult;
|
||||
}
|
||||
|
||||
private static String formatInfoLevelMsg(String methodInfo, String infoMsg) {
|
||||
return LOG_INFO_PREFIX + methodInfo + ": " + infoMsg;
|
||||
}
|
||||
|
||||
private static String formatErrorLevelMsg(String methodInfo) {
|
||||
return LOG_ERROR_PREFIX + methodInfo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public class IdGen
|
||||
{
|
||||
private long workerId;
|
||||
private long datacenterId;
|
||||
private long sequence = 0L;
|
||||
private long twepoch = 1288834974657L;
|
||||
private long workerIdBits = 5L;
|
||||
private long datacenterIdBits = 5L;
|
||||
private long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
||||
private long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
|
||||
private long sequenceBits = 12L;
|
||||
private long workerIdShift = sequenceBits;
|
||||
private long datacenterIdShift = sequenceBits + workerIdBits;
|
||||
private long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
|
||||
private long sequenceMask = -1L ^ (-1L << sequenceBits);
|
||||
private long lastTimestamp = -1L;
|
||||
private String suffix;
|
||||
private boolean flag;
|
||||
|
||||
private static class IdGenHolder {
|
||||
private static final IdGen instance = new IdGen();
|
||||
}
|
||||
|
||||
public static IdGen get(){
|
||||
return IdGenHolder.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串拼接id
|
||||
* @param suffix 字符串
|
||||
* @param flag true:前缀 false:后缀
|
||||
* @return
|
||||
*/
|
||||
public static IdGen get(String suffix,boolean flag){
|
||||
if(suffix == null || suffix.trim().length() == 0)
|
||||
return IdGenHolder.instance;
|
||||
else{
|
||||
return new IdGen(suffix,flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IdGen() {
|
||||
this(0L, 0L);
|
||||
}
|
||||
|
||||
public IdGen(String suffix,boolean flag){
|
||||
this.suffix = suffix;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public IdGen(long workerId, long datacenterId) {
|
||||
if (workerId > maxWorkerId || workerId < 0) {
|
||||
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
|
||||
}
|
||||
if (datacenterId > maxDatacenterId || datacenterId < 0) {
|
||||
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
|
||||
}
|
||||
this.workerId = workerId;
|
||||
this.datacenterId = datacenterId;
|
||||
}
|
||||
|
||||
public synchronized String nextId() {
|
||||
long timestamp = timeGen();
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(String.format(
|
||||
"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
if (lastTimestamp == timestamp) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
if (sequence == 0) {
|
||||
timestamp = tilNextMillis(lastTimestamp);
|
||||
}
|
||||
} else {
|
||||
sequence = 0L;
|
||||
}
|
||||
lastTimestamp = timestamp;
|
||||
|
||||
long serialNumber = ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift)
|
||||
| (workerId << workerIdShift) | sequence;
|
||||
|
||||
return (suffix == null || suffix.trim().length() == 0) ? serialNumber+"" : (flag ? (new StringBuffer()).append(suffix).append(serialNumber).toString() : (new StringBuffer()).append(serialNumber).append(suffix).toString());
|
||||
}
|
||||
|
||||
protected long tilNextMillis(long lastTimestamp) {
|
||||
long timestamp = timeGen();
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = timeGen();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
protected long timeGen() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
public class Log4jHandler extends AbstractRunningLogHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Log4jHandler.class);
|
||||
|
||||
public void info(String msg, String fqnOfCallingClass) {
|
||||
logger.info(fqnOfCallingClass, Level.INFO, msg, null);
|
||||
}
|
||||
|
||||
public void info(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
logger.info(fqnOfCallingClass, Level.INFO, msg, t);
|
||||
}
|
||||
|
||||
public void error(String msg, String fqnOfCallingClass) {
|
||||
logger.error(fqnOfCallingClass, Level.ERROR, msg, null);
|
||||
}
|
||||
|
||||
public void error(String msg, Throwable t, String fqnOfCallingClass) {
|
||||
logger.error(fqnOfCallingClass, Level.ERROR, msg, t);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public class LogDebug {
|
||||
|
||||
private final static String DEBUG_LOG_KEY = "-- LogHandler: ";
|
||||
|
||||
public static void debug(String msg) {
|
||||
System.err.println(DEBUG_LOG_KEY + msg);
|
||||
}
|
||||
|
||||
public static void debug(String msg, Throwable t) {
|
||||
System.err.println(DEBUG_LOG_KEY + msg);
|
||||
if (t != null)
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public interface LogHandler {
|
||||
|
||||
public void info(String msg, String fqnOfCallingClass);
|
||||
|
||||
public void info(String msg, Throwable t, String fqnOfCallingClass);
|
||||
|
||||
public void error(String msg, String fqnOfCallingClass);
|
||||
|
||||
public void error(String msg, Throwable t, String fqnOfCallingClass);
|
||||
|
||||
public void debug(String msg, String fqnOfCallingClass);
|
||||
|
||||
public void debug(String msg, Throwable t, String fqnOfCallingClass);
|
||||
|
||||
public void warning(String msg, String fqnOfCallingClass);
|
||||
|
||||
public void warning(String msg, Throwable t, String fqnOfCallingClass);
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class ObjectUtil extends SerializeTranscoder {
|
||||
@Override
|
||||
public byte[] serialize(Object value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException("Can't serialize null");
|
||||
}
|
||||
byte[] result = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
ObjectOutputStream os = null;
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
os = new ObjectOutputStream(bos);
|
||||
os.writeObject(value);
|
||||
os.close();
|
||||
bos.close();
|
||||
result = bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Non-serializable object", e);
|
||||
} finally {
|
||||
close(os);
|
||||
close(bos);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(byte[] in) {
|
||||
Object result = null;
|
||||
ByteArrayInputStream bis = null;
|
||||
ObjectInputStream is = null;
|
||||
try {
|
||||
if (in != null) {
|
||||
bis = new ByteArrayInputStream(in);
|
||||
is = new ObjectInputStream(bis);
|
||||
result = is.readObject();
|
||||
is.close();
|
||||
bis.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(is);
|
||||
close(bis);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean equals(Object o1, Object o2) {
|
||||
|
||||
if (o1 == o2) {
|
||||
return true;
|
||||
} else if (o1 == null || o2 == null) {
|
||||
return false;
|
||||
} else {
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Result implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1651614836984397356L;
|
||||
|
||||
private int code;
|
||||
|
||||
private Object result;
|
||||
|
||||
private String message;
|
||||
|
||||
public static final int SUCCESS_CODE = 0;
|
||||
|
||||
public static final int FAIL_CODE = 1;
|
||||
|
||||
private Result() {
|
||||
}
|
||||
|
||||
private Result(int code, Object result, String message) {
|
||||
this.code = code;
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
public static Result successResult(Object result) {
|
||||
return result(SUCCESS_CODE, result, "");
|
||||
}
|
||||
|
||||
public static Result successResult(Object records, Long recordSum, Long rowsOfPage) {
|
||||
return successResult(records, recordSum, rowsOfPage, null);
|
||||
}
|
||||
|
||||
public static Result successResult(Object records, Long recordSum, Long rowsOfPage, Object userData) {
|
||||
Map<String, Object> result = resultOfList(records, recordSum, rowsOfPage, userData);
|
||||
|
||||
return successResult(result);
|
||||
}
|
||||
|
||||
public static Map<String, Object> resultOfList(Object records, Long recordSum, Long rowsOfPage) {
|
||||
return resultOfList(records, recordSum, rowsOfPage, null);
|
||||
}
|
||||
|
||||
public static Map<String, Object> resultOfList(Object Obj, Long records, Long rowsOfPage, Object userData) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("rows", Obj);
|
||||
result.put("records", records);
|
||||
result.put("total", rowsOfPage);
|
||||
if (null != userData) {
|
||||
result.put("userdata", userData);
|
||||
}
|
||||
;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, Object> jqGridResult(List<?> list, long totalCount, int pageSize, int currPage,
|
||||
int totalPage) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("list", list);
|
||||
result.put("count", totalCount);
|
||||
result.put("next", currPage == totalPage ? currPage : currPage + 1);
|
||||
result.put("prev", currPage == 1 ? 1 : currPage - 1);
|
||||
result.put("first", 1);
|
||||
result.put("last", totalPage);
|
||||
result.put("pageSize", pageSize);
|
||||
result.put("pageNo", currPage);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param errorMsg
|
||||
* @return
|
||||
*/
|
||||
public static Result failResult(String errorMsg) {
|
||||
return result(FAIL_CODE, "", errorMsg);
|
||||
}
|
||||
|
||||
public static Result result(int code, Object result, String message) {
|
||||
Result res = new Result(code, result, message);
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
public abstract class SerializeTranscoder {
|
||||
|
||||
public abstract byte[] serialize(Object value);
|
||||
|
||||
public abstract Object deserialize(byte[] in);
|
||||
|
||||
public void close(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public class SystemConstant {
|
||||
|
||||
/** 初始密码*/
|
||||
public static final String INIT_PASSWORD = "123456";
|
||||
|
||||
/** 验证码常数*/
|
||||
public static final String KAPTCHA_SESSION_KEY = "KAPTCHA_SESSION_KEY";
|
||||
|
||||
/** 验证码常数*/
|
||||
public static final String SYSTEM_USER_CODE = "system";
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class XMLConfiguration {
|
||||
private Document document = null;
|
||||
|
||||
public boolean readConfigFile(String configFilename) {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
document = db.parse(configFilename);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (document == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean readConfigFile(InputStream stream) {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
document = db.parse(stream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (document == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Document getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
protected void setDocument(Document document) {
|
||||
this.document = document;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue