-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogFileHistory.java
74 lines (62 loc) · 1.85 KB
/
LogFileHistory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright distributed.net 1997-1999 - All Rights Reserved
// For use in distributed.net projects only.
// Any other distribution or use of this source violates copyright.
//
import java.io.*;
public class LogFileHistory implements Serializable
{
private static final int size = 4;
private File[] files = new File[size];
private static File logHistoryFile = new File("LogFileHistory.bin");
public LogFileHistory() {
}
protected boolean addFile(File f) {
if (!exists(f)) {
for (int i = files.length-1; i > 0; i--) {
files[i] = files[i-1];
}
files[0] = f;
return true;
} else {
return false;
}
}
protected boolean exists(File f) {
for (int i = 0; i < files.length; i++) {
if (files[i] != null && files[i].equals(f)) {
return true;
}
}
return false;
}
protected File[] getFiles() {
return files;
}
protected void save() {
try {
FileOutputStream out = new FileOutputStream(logHistoryFile);
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(this);
s.flush();
} catch(IOException ioe) {
System.out.println(ioe.toString());
}
}
protected static LogFileHistory open()
{
LogFileHistory lfh = null;
try {
FileInputStream in = new FileInputStream(logHistoryFile);
ObjectInputStream s = new ObjectInputStream(in);
lfh = (LogFileHistory)s.readObject();
} catch (IOException ioe) {
} catch (ClassNotFoundException cnfe) {
} finally {
if (lfh == null) {
return new LogFileHistory();
} else {
return lfh;
}
}
}
}