1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.net;
21
22 import java.io.BufferedWriter;
23 import java.io.FileWriter;
24 import java.io.IOException;
25
26 public class OpenNapServerFileWriter implements OpenNapServerWriter {
27
28
29
30 private BufferedWriter out = null;
31 private String filename;
32
33
34
35 public OpenNapServerFileWriter(String filename)
36 {
37 this.filename = filename;
38 }
39
40
41
42 public void close()
43 {
44 try {
45 if (out != null) {
46 out.close();
47 }
48 }
49 catch (IOException e) {
50 }
51 }
52
53 public void open() throws IOException
54 {
55 out = new BufferedWriter(new FileWriter(filename, false));
56 }
57
58 public void write(OpenNapServer s) throws IOException
59 {
60 StringBuffer sb = new StringBuffer();
61 append(sb, s.getHost());
62 append(sb, s.getPort() + "");
63 append(sb, s.getNetwork().getName());
64 append(sb, (s.isLoginCustomized()) ? s.getNick() : "");
65 append(sb, (s.isLoginCustomized()) ? s.getPassword() : "");
66 append(sb, (s.isLoginCustomized()) ? s.getEmail() : "");
67 append(sb, (s.isRedirector()) ? "true" : "false");
68 append(sb, s.getAutoJoinChannels());
69 append(sb, s.getLastConnect()+ "");
70 append(sb, (s.getAutoConnect()) ? "true" : "false");
71 append(sb, "");
72
73 out.write(sb.toString());
74 out.newLine();
75 }
76
77 private static void append(StringBuffer sb, String s)
78 {
79 sb.append("\"");
80 sb.append(s);
81 sb.append("\" ");
82 }
83
84 }