]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/security/DefaultSecuredProvider.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / security / DefaultSecuredProvider.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\r
10 /*  PJIRC is free software; you can redistribute     */\r
11 /*  it and/or modify it under the terms of the GNU   */\r
12 /*  General Public License as published by the       */\r
13 /*  Free Software Foundation; version 2 or later of  */\r
14 /*  the License.                                     */\r
15 /*                                                   */\r
16 /*  PJIRC is distributed in the hope that it will    */\r
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */\r
18 /*  even the implied warranty of MERCHANTABILITY or  */\r
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */\r
20 /*  General Public License for more details.         */\r
21 /*                                                   */\r
22 /*  You should have received a copy of the GNU       */\r
23 /*  General Public License along with PJIRC; if      */\r
24 /*  not, write to the Free Software Foundation,      */\r
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */\r
26 /*  MA  02111-1307  USA                              */\r
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc.security;\r
31 \r
32 import java.awt.FileDialog;\r
33 import java.awt.Frame;\r
34 import java.io.File;\r
35 import java.io.FileInputStream;\r
36 import java.io.FileOutputStream;\r
37 import java.io.IOException;\r
38 import java.net.InetAddress;\r
39 import java.net.ServerSocket;\r
40 import java.net.Socket;\r
41 import java.net.UnknownHostException;\r
42 \r
43 /**\r
44  * Default secured provider.\r
45  */\r
46 public class DefaultSecuredProvider implements SecuredProvider {\r
47 \r
48         @Override\r
49         public Socket getSocket(String host, Integer port) throws UnknownHostException, IOException {\r
50                 return new Socket(host, port.intValue());\r
51         }\r
52 \r
53         @Override\r
54         public ServerSocket getServerSocket(Integer port) throws IOException {\r
55                 return new ServerSocket(port.intValue());\r
56         }\r
57 \r
58         @Override\r
59         public FileInputStream getFileInputStream(File file) throws IOException {\r
60                 return new FileInputStream(file);\r
61         }\r
62 \r
63         @Override\r
64         public FileOutputStream getFileOutputStream(File file) throws IOException {\r
65                 return new FileOutputStream(file);\r
66         }\r
67 \r
68         @Override\r
69         public Integer getFileSize(File file) {\r
70                 return new Integer((int) file.length());\r
71         }\r
72 \r
73         @Override\r
74         public File getLoadFile(String title) {\r
75                 Frame f = new Frame();\r
76                 FileDialog dlg = new FileDialog(f, title, FileDialog.LOAD);\r
77                 dlg.show();\r
78                 File ans = null;\r
79                 if (dlg.getFile() != null)\r
80                         ans = new File(dlg.getDirectory() + dlg.getFile());\r
81                 dlg.hide();\r
82                 dlg.dispose();\r
83                 f.dispose();\r
84                 return ans;\r
85         }\r
86 \r
87         @Override\r
88         public File getSaveFile(String title) {\r
89                 Frame f = new Frame();\r
90                 FileDialog dlg = new FileDialog(f, title, FileDialog.SAVE);\r
91                 dlg.show();\r
92                 File ans = null;\r
93                 if (dlg.getFile() != null)\r
94                         ans = new File(dlg.getDirectory() + dlg.getFile());\r
95                 dlg.hide();\r
96                 dlg.dispose();\r
97                 f.dispose();\r
98                 return ans;\r
99         }\r
100 \r
101         @Override\r
102         public File getSaveFile(String file, String title) {\r
103                 Frame f = new Frame();\r
104                 FileDialog dlg = new FileDialog(f, title, FileDialog.SAVE);\r
105                 dlg.setFile(file);\r
106                 dlg.show();\r
107                 File ans = null;\r
108                 if (dlg.getFile() != null)\r
109                         ans = new File(dlg.getDirectory() + dlg.getFile());\r
110                 dlg.hide();\r
111                 dlg.dispose();\r
112                 f.dispose();\r
113                 return ans;\r
114         }\r
115 \r
116         @Override\r
117         public InetAddress getLocalHost() throws UnknownHostException {\r
118                 InetAddress[] addresses = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());\r
119                 return addresses[addresses.length - 1];\r
120         }\r
121 \r
122         @Override\r
123         public String resolve(InetAddress addr) {\r
124                 return addr.getHostName();\r
125         }\r
126 \r
127         @Override\r
128         public boolean tryProvider() {\r
129                 return true;\r
130         }\r
131 \r
132         @Override\r
133         public String getName() {\r
134                 return "Default Security Provider";\r
135         }\r
136 \r
137 }\r