1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\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
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
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
28 /*****************************************************/
\r
30 package irc.security;
\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
44 * Default secured provider.
\r
46 public class DefaultSecuredProvider implements SecuredProvider {
\r
49 public Socket getSocket(String host, Integer port) throws UnknownHostException, IOException {
\r
50 return new Socket(host, port.intValue());
\r
54 public ServerSocket getServerSocket(Integer port) throws IOException {
\r
55 return new ServerSocket(port.intValue());
\r
59 public FileInputStream getFileInputStream(File file) throws IOException {
\r
60 return new FileInputStream(file);
\r
64 public FileOutputStream getFileOutputStream(File file) throws IOException {
\r
65 return new FileOutputStream(file);
\r
69 public Integer getFileSize(File file) {
\r
70 return new Integer((int) file.length());
\r
74 public File getLoadFile(String title) {
\r
75 Frame f = new Frame();
\r
76 FileDialog dlg = new FileDialog(f, title, FileDialog.LOAD);
\r
79 if (dlg.getFile() != null)
\r
80 ans = new File(dlg.getDirectory() + dlg.getFile());
\r
88 public File getSaveFile(String title) {
\r
89 Frame f = new Frame();
\r
90 FileDialog dlg = new FileDialog(f, title, FileDialog.SAVE);
\r
93 if (dlg.getFile() != null)
\r
94 ans = new File(dlg.getDirectory() + dlg.getFile());
\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
108 if (dlg.getFile() != null)
\r
109 ans = new File(dlg.getDirectory() + dlg.getFile());
\r
117 public InetAddress getLocalHost() throws UnknownHostException {
\r
118 InetAddress[] addresses = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
\r
119 return addresses[addresses.length - 1];
\r
123 public String resolve(InetAddress addr) {
\r
124 return addr.getHostName();
\r
128 public boolean tryProvider() {
\r
133 public String getName() {
\r
134 return "Default Security Provider";
\r