Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit ec303c6

Browse files
committed
fix bug
1 parent 037fad5 commit ec303c6

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/main/java/com/zhazhapan/util/AopLogUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
**/
1111
public class AopLogUtils {
1212

13+
private AopLogUtils() {}
14+
1315
/**
1416
* 获取 {@link AopLog}注解中的描述
1517
*

src/main/java/com/zhazhapan/util/BeanUtils.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ public static <T> T deserialize(String file, Class<T> clazz) throws IOException,
151151
* @since 1.0.8
152152
*/
153153
public static Object deserialize(String file) throws IOException, ClassNotFoundException {
154-
FileInputStream fileIn = new FileInputStream(file);
155-
ObjectInputStream in = new ObjectInputStream(fileIn);
156-
Object object = in.readObject();
157-
in.close();
158-
fileIn.close();
154+
Object object;
155+
try (FileInputStream fileIn = new FileInputStream(file); ObjectInputStream in = new ObjectInputStream(fileIn)) {
156+
object = in.readObject();
157+
}
159158
return object;
160159
}
161160

@@ -170,11 +169,10 @@ public static Object deserialize(String file) throws IOException, ClassNotFoundE
170169
*/
171170
public static void serialize(Object object, String file) throws Exception {
172171
if (object instanceof Serializable) {
173-
FileOutputStream fileOut = new FileOutputStream(file);
174-
ObjectOutputStream out = new ObjectOutputStream(fileOut);
175-
out.writeObject(object);
176-
out.close();
177-
fileOut.close();
172+
try (FileOutputStream fileOut = new FileOutputStream(file); ObjectOutputStream out =
173+
new ObjectOutputStream(fileOut)) {
174+
out.writeObject(object);
175+
}
178176
} else {
179177
throw new Exception(object.getClass().getName() + " doesn't implements serializable interface");
180178
}

src/main/java/com/zhazhapan/util/FileExecutor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ public static void watchFile(String file, SimpleHutoolWatcher watcher, boolean s
5252
if (shouldFirstExecute) {
5353
watcher.doSomething();
5454
}
55-
WatchMonitor.createAll(file, new SimpleWatcher() {
55+
SimpleWatcher simpleWatcher = new SimpleWatcher() {
5656
@Override
5757
public void onModify(WatchEvent<?> event, Path currentPath) {
5858
watcher.onModify(event, currentPath);
5959
watcher.doSomething();
6060
}
61-
}).start();
61+
};
62+
try (WatchMonitor monitor = WatchMonitor.createAll(file, simpleWatcher)) {
63+
monitor.start();
64+
}
6265
}
6366

6467
/**

0 commit comments

Comments
 (0)