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 WSXFileWriter implements OpenNapServerWriter, WSXFile {
27
28
29
30 private BufferedWriter out = null;
31 private String filename;
32
33
34
35 public WSXFileWriter(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 server) throws IOException
59 {
60 out.write(NETWORK);
61 out.write(NAME_VALUE_DELIM);
62 out.write((server.getNetworkName().length() == 0)
63 ? NOT_AVAILABLE
64 : server.getNetworkName());
65 out.newLine();
66
67 out.write(TYPE);
68 out.write(NAME_VALUE_DELIM);
69 out.write(server.isRedirector() ? TYPE_META : TYPE_NORMAL);
70 out.newLine();
71
72 out.write(PORT);
73 out.write(NAME_VALUE_DELIM);
74 out.write(Integer.toString(server.getPort()));
75 out.newLine();
76
77 out.write(AUTO_CONNECT);
78 out.write(NAME_VALUE_DELIM);
79 out.write("false");
80 out.newLine();
81
82 if (server.isLoginCustomized()) {
83 out.write(USERNAME);
84 out.write(NAME_VALUE_DELIM);
85 out.write(server.getNick());
86 out.newLine();
87
88 out.write(USER_PASSWORD);
89 out.write(NAME_VALUE_DELIM);
90 out.write(server.getPassword());
91 out.newLine();
92 }
93
94 out.write(ADDRESS);
95 out.write(NAME_VALUE_DELIM);
96 out.write(server.getHost());
97 out.newLine();
98 }
99
100 }