Skip to content

Commit

Permalink
Modify : 增加Log输出
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyZzh committed Sep 24, 2016
1 parent d87fcfb commit 6f80b81
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 56 deletions.
5 changes: 5 additions & 0 deletions okra-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
<artifactId>flex-messaging-common</artifactId>
<version>4.7.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
19 changes: 14 additions & 5 deletions okra-core/src/main/java/org/ogcs/app/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.ogcs.app;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
Expand All @@ -24,14 +26,21 @@
import java.lang.reflect.Type;

/**
* @author TinyZ
* Spring Application Context.
*
* @author TinyZ.
* @since 1.0
*/
@Service("AppContext")
public class AppContext implements ApplicationContextAware {
public final class AppContext implements ApplicationContextAware {

private static final Logger LOG = LogManager.getLogger(AppContext.class);
private static ApplicationContext context;

private AppContext() {
// no-op
}

/**
* Get bean
*
Expand All @@ -46,13 +55,13 @@ public static <T> T getBean(String beanName, Class<T> clz) {
try {
return context.getBean(beanName, clz);
} catch (Exception e) {
e.printStackTrace();
LOG.info("Unknown Bean Name : " + beanName + ", Class : " + clz.toString(), e);
}
return null;
}

/**
* Get bean
* Get bean by bean name.
*
* @param beanName The bean name.
* @return Return the bean
Expand All @@ -65,7 +74,7 @@ public static Object getBean(String beanName) {
try {
bean = context.getBean(beanName);
} catch (Exception e) {
e.printStackTrace();
LOG.info("Unknown Bean Name : " + beanName, e);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
import java.util.List;

/**
* Decode Amf3 {@link ByteBuf} to Java Object.
* @author : TinyZ.
* @email : tinyzzh815@gmail.com
* @date : 2016/5/17
* @since 1.0
*/
@Sharable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
import java.util.List;

/**
* Encode Java Object to Amf3 {@link ByteBuf}.
* @author : TinyZ.
* @email : tinyzzh815@gmail.com
* @date : 2016/5/17
* @since 1.0
*/
@Sharable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Logic processor.
* @author TinyZ.
* @date 2016-07-04.
* @since 1.0
*/
public class LogicProcessor implements Runnable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* 基于同步消息队列的单生产者的Disruptor模式
*
* @author TinyZ.
* @since 1.0.
* @since 1.0
*/
@Sharable
public abstract class MessageQueueHandler<O> extends SimpleChannelInboundHandler<O> {
Expand Down
5 changes: 3 additions & 2 deletions okra-core/src/main/java/org/ogcs/utilities/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import java.util.LinkedList;

/**
* 时间日期相关应用
* 时间日期相关应用(旧版本). 推荐{@link TimeV8Util}
*
* @author zzh 2013-8-19
* @author TinyZ.
* @since 1.0
*/
public class DateUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,84 @@

package org.ogcs.utilities;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
* File read utilities.
*
* @author tinyZ
* @version 1.0
* @author TinyZ
* @since 1.0
*/
public class SmallFileReader {
public final class TxtReader {

private static final Logger LOG = LogManager.getLogger(TxtReader.class);

private TxtReader() {
// no-op
}

/**
* 读取文件
*
* @param filePath
* @return
* @throws IOException
*/
public static String readSmallFile(String filePath) throws IOException {
if ((filePath == null) || (filePath.equals(""))) {
public static String readFile(String path) throws IOException {
if ((path == null) || (path.equals(""))) {
return null;
}
File file = new File(path);
if (!file.exists()) {
return null;
}
File smallFile = new File(filePath);
return readSmallFile(smallFile);
return readFile(file, Charset.forName("UTF-8"));
}

/**
* 读取文件
*
* @param smallFile
* @return
* @throws IOException
*/
public static String readSmallFile(File smallFile) throws IOException {
InputStreamReader reader = new InputStreamReader(new FileInputStream(smallFile), "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuffer buf = new StringBuffer();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
buf.append(line);
public static String readFile(File file, Charset charset) {
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), charset);
BufferedReader br = new BufferedReader(reader)) {
StringBuilder buf = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
buf.append(line);
}
return buf.toString();
} catch (IOException e) {
LOG.error("TxtReader read file error. Path : " + file.getPath(), e);
}
bufferedReader.close();
reader.close();
return buf.toString();
return null;
}

/**
* 读取文件
*
* @param filePath
* @return
* @throws IOException
*/
public static byte[] readFileBytes(String filePath) throws IOException {
if ((filePath == null) || (filePath.equals(""))) {
public static byte[] readFileBytes(String path) throws IOException {
if ((path == null) || (path.equals(""))) {
return null;
}
File smallFile = new File(filePath);
return readFileBytes(smallFile);
File file = new File(path);
if (!file.exists()) {
return null;
}
return readFileBytes(file);
}

/**
* 读取文件
*
* @param smallFile
* @return
* @throws IOException
*/
public static byte[] readFileBytes(File smallFile) throws IOException {
public static byte[] readFileBytes(File file) throws IOException {
ByteArrayOutputStream ous = null;
InputStream ios = null;
try {
byte[] buffer = new byte[4096];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(smallFile);
ios = new FileInputStream(file);
int read = 0;
while ((read = ios.read(buffer)) != -1)
ous.write(buffer, 0, read);
Expand All @@ -112,12 +114,12 @@ public static byte[] readFileBytes(File smallFile) throws IOException {
/**
* 获取文件夹路径下的全部后缀名为suffix的文件的路径
*
* @param path
* @param suffix
* @return
* @param path The folder path.
* @param suffix The file suffix.
* @return Return the path of all files under the folder.
*/
public static List<String> listFile(String path, String suffix) {
List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<>();
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
Expand Down

0 comments on commit 6f80b81

Please sign in to comment.