KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > microedition > io > Connector


1
2 /*
3  * MicroEmulator
4  * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20  
21 package javax.microedition.io;
22
23 import java.io.DataInputStream;
24 import java.io.DataOutputStream;
25 import java.io.InputStream;
26 import java.io.IOException;
27 import java.io.OutputStream;
28
29 import com.barteo.cldc.ClosedConnection;
30
31
32 public class Connector
33 {
34
35     public static final int READ = 1;
36     public static final int WRITE = 2;
37     public static final int READ_WRITE = 3;
38     
39     
40     public static Connection open(String name)
41       throws IOException
42   {
43     return open(name, READ_WRITE, false);
44   }
45   
46   
47   public static Connection open(String name, int mode)
48       throws IOException
49   {
50     return open(name, mode, false);
51   }
52   
53   
54   public static Connection open(String name, int mode, boolean timeouts)
55       throws IOException
56   {
57     ClosedConnection cn;
58     try {
59       Class cl = Class.forName(
60           "com.barteo.cldc." + name.substring(0, name.indexOf(':')) + ".Connection");
61       cn = (ClosedConnection) cl.newInstance();
62     } catch (ClassNotFoundException ex) {
63       System.err.println(ex);
64       throw new ConnectionNotFoundException();
65     } catch (InstantiationException ex) {
66       System.err.println(ex);
67       throw new ConnectionNotFoundException();
68     } catch (IllegalAccessException ex) {
69       System.err.println(ex);
70       throw new ConnectionNotFoundException();
71     }
72     return cn.open(name);
73   }
74   
75   
76   public static DataInputStream openDataInputStream(String name)
77       throws IOException
78   {
79     InputConnection cn = (InputConnection) open(name);
80     
81     return cn.openDataInputStream();
82   }
83   
84   
85   public static DataOutputStream openDataOutputStream(String name)
86       throws IOException
87   {
88     OutputConnection cn = (OutputConnection) open(name);
89     
90     return cn.openDataOutputStream();
91   }
92   
93   
94   public static InputStream openInputStream(String name)
95       throws IOException
96   {
97     InputConnection cn = (InputConnection) open(name);
98     
99     return cn.openInputStream();
100   }
101   
102     
103     public static OutputStream openOutputStream(String name)
104       throws IOException
105   {
106     OutputConnection cn = (OutputConnection) open(name);
107     
108     return cn.openOutputStream();
109   }
110   
111 }
112
Popular Tags