1 2 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 |