Skip to content

Commit 6f80b81

Browse files
committed
Modify : 增加Log输出
1 parent d87fcfb commit 6f80b81

File tree

8 files changed

+71
-56
lines changed

8 files changed

+71
-56
lines changed

okra-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@
150150
<artifactId>flex-messaging-common</artifactId>
151151
<version>4.7.2</version>
152152
</dependency>
153+
<dependency>
154+
<groupId>junit</groupId>
155+
<artifactId>junit</artifactId>
156+
<scope>test</scope>
157+
</dependency>
153158
</dependencies>
154159

155160
</project>

okra-core/src/main/java/org/ogcs/app/AppContext.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.ogcs.app;
1818

19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
1921
import org.springframework.beans.BeansException;
2022
import org.springframework.context.ApplicationContext;
2123
import org.springframework.context.ApplicationContextAware;
@@ -24,14 +26,21 @@
2426
import java.lang.reflect.Type;
2527

2628
/**
27-
* @author TinyZ
29+
* Spring Application Context.
30+
*
31+
* @author TinyZ.
2832
* @since 1.0
2933
*/
3034
@Service("AppContext")
31-
public class AppContext implements ApplicationContextAware {
35+
public final class AppContext implements ApplicationContextAware {
3236

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

40+
private AppContext() {
41+
// no-op
42+
}
43+
3544
/**
3645
* Get bean
3746
*
@@ -46,13 +55,13 @@ public static <T> T getBean(String beanName, Class<T> clz) {
4655
try {
4756
return context.getBean(beanName, clz);
4857
} catch (Exception e) {
49-
e.printStackTrace();
58+
LOG.info("Unknown Bean Name : " + beanName + ", Class : " + clz.toString(), e);
5059
}
5160
return null;
5261
}
5362

5463
/**
55-
* Get bean
64+
* Get bean by bean name.
5665
*
5766
* @param beanName The bean name.
5867
* @return Return the bean
@@ -65,7 +74,7 @@ public static Object getBean(String beanName) {
6574
try {
6675
bean = context.getBean(beanName);
6776
} catch (Exception e) {
68-
e.printStackTrace();
77+
LOG.info("Unknown Bean Name : " + beanName, e);
6978
}
7079
return bean;
7180
}

okra-core/src/main/java/org/ogcs/netty/handler/codec/Amf3ToObjectDecoder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
import java.util.List;
2929

3030
/**
31+
* Decode Amf3 {@link ByteBuf} to Java Object.
3132
* @author : TinyZ.
32-
* @email : tinyzzh815@gmail.com
33-
* @date : 2016/5/17
3433
* @since 1.0
3534
*/
3635
@Sharable

okra-core/src/main/java/org/ogcs/netty/handler/codec/ObjectToAmf3Encoder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
import java.util.List;
2929

3030
/**
31+
* Encode Java Object to Amf3 {@link ByteBuf}.
3132
* @author : TinyZ.
32-
* @email : tinyzzh815@gmail.com
33-
* @date : 2016/5/17
3433
* @since 1.0
3534
*/
3635
@Sharable

okra-core/src/main/java/org/ogcs/netty/handler/mq/LogicProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/**
3636
* Logic processor.
3737
* @author TinyZ.
38-
* @date 2016-07-04.
38+
* @since 1.0
3939
*/
4040
public class LogicProcessor implements Runnable {
4141

okra-core/src/main/java/org/ogcs/netty/handler/mq/MessageQueueHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* 基于同步消息队列的单生产者的Disruptor模式
3131
*
3232
* @author TinyZ.
33-
* @since 1.0.
33+
* @since 1.0
3434
*/
3535
@Sharable
3636
public abstract class MessageQueueHandler<O> extends SimpleChannelInboundHandler<O> {

okra-core/src/main/java/org/ogcs/utilities/DateUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import java.util.LinkedList;
2323

2424
/**
25-
* 时间日期相关应用
25+
* 时间日期相关应用(旧版本). 推荐{@link TimeV8Util}
2626
*
27-
* @author zzh 2013-8-19
27+
* @author TinyZ.
28+
* @since 1.0
2829
*/
2930
public class DateUtil {
3031

okra-core/src/main/java/org/ogcs/utilities/SmallFileReader.java renamed to okra-core/src/main/java/org/ogcs/utilities/TxtReader.java

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,82 +16,84 @@
1616

1717
package org.ogcs.utilities;
1818

19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
21+
1922
import java.io.*;
23+
import java.nio.charset.Charset;
2024
import java.util.ArrayList;
2125
import java.util.List;
2226

2327
/**
2428
* File read utilities.
2529
*
26-
* @author tinyZ
27-
* @version 1.0
30+
* @author TinyZ
31+
* @since 1.0
2832
*/
29-
public class SmallFileReader {
33+
public final class TxtReader {
34+
35+
private static final Logger LOG = LogManager.getLogger(TxtReader.class);
36+
37+
private TxtReader() {
38+
// no-op
39+
}
3040

3141
/**
3242
* 读取文件
33-
*
34-
* @param filePath
35-
* @return
36-
* @throws IOException
3743
*/
38-
public static String readSmallFile(String filePath) throws IOException {
39-
if ((filePath == null) || (filePath.equals(""))) {
44+
public static String readFile(String path) throws IOException {
45+
if ((path == null) || (path.equals(""))) {
46+
return null;
47+
}
48+
File file = new File(path);
49+
if (!file.exists()) {
4050
return null;
4151
}
42-
File smallFile = new File(filePath);
43-
return readSmallFile(smallFile);
52+
return readFile(file, Charset.forName("UTF-8"));
4453
}
4554

4655
/**
4756
* 读取文件
48-
*
49-
* @param smallFile
50-
* @return
51-
* @throws IOException
5257
*/
53-
public static String readSmallFile(File smallFile) throws IOException {
54-
InputStreamReader reader = new InputStreamReader(new FileInputStream(smallFile), "UTF-8");
55-
BufferedReader bufferedReader = new BufferedReader(reader);
56-
StringBuffer buf = new StringBuffer();
57-
String line = null;
58-
while ((line = bufferedReader.readLine()) != null) {
59-
buf.append(line);
58+
public static String readFile(File file, Charset charset) {
59+
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), charset);
60+
BufferedReader br = new BufferedReader(reader)) {
61+
StringBuilder buf = new StringBuilder();
62+
String line = null;
63+
while ((line = br.readLine()) != null) {
64+
buf.append(line);
65+
}
66+
return buf.toString();
67+
} catch (IOException e) {
68+
LOG.error("TxtReader read file error. Path : " + file.getPath(), e);
6069
}
61-
bufferedReader.close();
62-
reader.close();
63-
return buf.toString();
70+
return null;
6471
}
6572

6673
/**
6774
* 读取文件
68-
*
69-
* @param filePath
70-
* @return
71-
* @throws IOException
7275
*/
73-
public static byte[] readFileBytes(String filePath) throws IOException {
74-
if ((filePath == null) || (filePath.equals(""))) {
76+
public static byte[] readFileBytes(String path) throws IOException {
77+
if ((path == null) || (path.equals(""))) {
7578
return null;
7679
}
77-
File smallFile = new File(filePath);
78-
return readFileBytes(smallFile);
80+
File file = new File(path);
81+
if (!file.exists()) {
82+
return null;
83+
}
84+
return readFileBytes(file);
7985
}
8086

8187
/**
8288
* 读取文件
83-
*
84-
* @param smallFile
85-
* @return
86-
* @throws IOException
8789
*/
88-
public static byte[] readFileBytes(File smallFile) throws IOException {
90+
public static byte[] readFileBytes(File file) throws IOException {
8991
ByteArrayOutputStream ous = null;
9092
InputStream ios = null;
9193
try {
9294
byte[] buffer = new byte[4096];
9395
ous = new ByteArrayOutputStream();
94-
ios = new FileInputStream(smallFile);
96+
ios = new FileInputStream(file);
9597
int read = 0;
9698
while ((read = ios.read(buffer)) != -1)
9799
ous.write(buffer, 0, read);
@@ -112,12 +114,12 @@ public static byte[] readFileBytes(File smallFile) throws IOException {
112114
/**
113115
* 获取文件夹路径下的全部后缀名为suffix的文件的路径
114116
*
115-
* @param path
116-
* @param suffix
117-
* @return
117+
* @param path The folder path.
118+
* @param suffix The file suffix.
119+
* @return Return the path of all files under the folder.
118120
*/
119121
public static List<String> listFile(String path, String suffix) {
120-
List<String> list = new ArrayList<String>();
122+
List<String> list = new ArrayList<>();
121123
File file = new File(path);
122124
if (file.isDirectory()) {
123125
File[] files = file.listFiles();

0 commit comments

Comments
 (0)