Skip to content

Commit f2127d0

Browse files
committed
fixing EOFException when force killing terminal
1 parent 2623e79 commit f2127d0

5 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎koans/app/lib/file-compiler.jar‎

0 Bytes
Binary file not shown.

‎koans/app/lib/file-monitor.jar‎

75 Bytes
Binary file not shown.

‎koans/app/lib/koans.jar‎

0 Bytes
Binary file not shown.

‎koans/app/lib/util.jar‎

0 Bytes
Binary file not shown.

‎lib/file-monitor/src/com/sandwich/util/io/DataFileHelper.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sandwich.util.io;
22

3+
import java.io.EOFException;
34
import java.io.File;
45
import java.io.FileInputStream;
56
import java.io.FileOutputStream;
@@ -50,9 +51,10 @@ public T read(){
5051
try {
5152
return lastRetrieval = (T)objectInputStream.readObject();
5253
}catch(UTFDataFormatException x){
53-
dataFile.delete();
54-
dataFile.createNewFile();
55-
write(defaultState);
54+
createNewFile(dataFile);
55+
return defaultState;
56+
}catch(EOFException x){
57+
createNewFile(dataFile);
5658
return defaultState;
5759
}
5860
}else{
@@ -78,6 +80,12 @@ public T read(){
7880
}
7981
}
8082

83+
private void createNewFile(File dataFile) throws IOException {
84+
dataFile.delete();
85+
dataFile.createNewFile();
86+
write(defaultState);
87+
}
88+
8189
public void write(T state){
8290
ObjectOutputStream objectOutputStream = null;
8391
try {

0 commit comments

Comments
 (0)