Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/microedition/io/Connector.java


1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library 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 GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19   
20  package javax.microedition.io;
21  
22  import java.io.DataInputStream;
23  import java.io.DataOutputStream;
24  import java.io.InputStream;
25  import java.io.IOException;
26  import java.io.OutputStream;
27  
28  import com.barteo.cldc.ClosedConnection;
29  
30  
31  public class Connector
32  {
33  
34    public static final int READ = 1;
35    public static final int WRITE = 2;
36    public static final int READ_WRITE = 3;
37    
38    
39    public static Connection open(String name)
40        throws IOException
41    {
42      return open(name, READ_WRITE, false);
43    }
44    
45    
46    public static Connection open(String name, int mode)
47        throws IOException
48    {
49      return open(name, mode, false);
50    }
51    
52    
53    public static Connection open(String name, int mode, boolean timeouts)
54        throws IOException
55    {
56      ClosedConnection cn;
57      try {
58        Class cl = Class.forName(
59            "com.barteo.cldc." + name.substring(0, name.indexOf(':')) + ".Connection");
60        cn = (ClosedConnection) cl.newInstance();
61      } catch (ClassNotFoundException ex) {
62        System.err.println(ex);
63        throw new ConnectionNotFoundException();
64      } catch (InstantiationException ex) {
65        System.err.println(ex);
66        throw new ConnectionNotFoundException();
67      } catch (IllegalAccessException ex) {
68        System.err.println(ex);
69        throw new ConnectionNotFoundException();
70      }
71      return cn.open(name);
72    }
73    
74    
75    public static DataInputStream openDataInputStream(String name)
76        throws IOException
77    {
78      InputConnection cn = (InputConnection) open(name);
79      
80      return cn.openDataInputStream();
81    }
82    
83    
84    public static DataOutputStream openDataOutputStream(String name)
85        throws IOException
86    {
87      OutputConnection cn = (OutputConnection) open(name);
88      
89      return cn.openDataOutputStream();
90    }
91    
92    
93    public static InputStream openInputStream(String name)
94        throws IOException
95    {
96      InputConnection cn = (InputConnection) open(name);
97      
98      return cn.openInputStream();
99    }
100   
101     
102   public static OutputStream openOutputStream(String name)
103       throws IOException
104   {
105     OutputConnection cn = (OutputConnection) open(name);
106     
107     return cn.openOutputStream();
108   }
109   
110 }