View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Data Field(s) ---
29  
30      private BufferedWriter out = null;
31      private String filename;
32  
33      //--- Constructor(s) ---
34  	
35      public WSXFileWriter(String filename)
36      {
37  		this.filename = filename;
38      }
39  
40      //--- Method(s) ---
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 }