Skip to content

Commit 8b38360

Browse files
realDuYuanChaogithub-actions
andauthored
fixed LGTM (examplehub#73)
* fixed LGTM * fixed try resource management LGTM * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 97629dc commit 8b38360

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/main/java/com/examplehub/basics/SerializableExample.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@
55
public class SerializableExample {
66
public static void main(String[] args) throws IOException, ClassNotFoundException {
77
User user = new User(1, "root", "root");
8-
try (ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream("user.data"))) {
8+
FileOutputStream fos = null;
9+
ObjectOutputStream stream = null;
10+
try {
11+
fos = new FileOutputStream("user.data");
12+
stream = new ObjectOutputStream(fos);
913
stream.writeObject(user);
14+
} finally {
15+
if (stream != null) {
16+
stream.close();
17+
}
18+
if (fos != null) {
19+
fos.close();
20+
}
1021
}
1122

12-
try (ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("user.data"))) {
13-
User newUser = (User) inputStream.readObject();
23+
ObjectInputStream ois = null;
24+
FileInputStream fis = null;
25+
try {
26+
fis = new FileInputStream("user.data");
27+
ois = new ObjectInputStream(fis);
28+
User newUser = (User) ois.readObject();
1429
System.out.println(newUser); /* User{id=1, username='root', password='root'} */
30+
} finally {
31+
if (fis != null) {
32+
stream.close();
33+
}
34+
if (ois != null) {
35+
ois.close();
36+
}
1537
}
1638
}
1739
}

src/main/java/com/examplehub/projecteuler/Problem41.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ public static long solution1() {
1616
if (CharToInt.toInt(chars[j + 1]) - CharToInt.toInt(chars[j]) != 1) {
1717
break;
1818
}
19-
if (j == chars.length - 1) {
20-
System.out.println(i);
21-
return i;
22-
}
2319
}
2420
}
2521
return 0;

0 commit comments

Comments
 (0)