⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connector.java

📁 J2me唆哈的代码
💻 JAVA
字号:
/*
 * Created on 2005-8-15 by pcy
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package javax.microedition.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

import a.a.a.midp.io.ConnectionBaseInterface;


/**
 * @author pcy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Connector {

    public static final int READ=1;

    public static final int WRITE=2;
        
    public static final int READ_WRITE=3;
    
    private static String platform = System.getProperty("microedition.platform");
    private static boolean j2me = false;
    private static String classRoot;


    static 
    {
        if(System.getProperty("microedition.configuration") != null)
            j2me = true;
        classRoot = System.getProperty("javax.microedition.io.Connector.protocolpath");
        if(classRoot == null)
            classRoot = "com.booqio.emulator.io";
    }
    
    private Connector()
    {
    }

    public static Connection open(String name)
        throws IOException
    {
        return open(name, READ_WRITE);
    }

    public static Connection open(String name, int mode)
        throws IOException
    {
        return open(name, mode, false);
    }

    public static Connection open(String name, int mode, boolean timeouts)
        throws IOException
    {

        if(platform != null){
            try{
                return openPrim(name, mode, timeouts, platform);
            }
            catch(ClassNotFoundException classnotfoundexception) { }
        }
        try{
            return openPrim(name, mode, timeouts, j2me ? "j2me" : "j2se");
        }catch(ClassNotFoundException classnotfoundexception1){
            throw new ConnectionNotFoundException("The requested protocol does not exist " + name);
        }
    }

    private static Connection openPrim(String name, int mode, boolean flag, String s1)
        throws IOException, ClassNotFoundException
    {
    	System.out.println("Url="+name);
        if(name == null){
            throw new IllegalArgumentException("Null URL");
        }
        int j = name.indexOf(58);//find ':'
        if(j < 1)
            throw new IllegalArgumentException("no ':' in URL");
        try
        {
            String s2 = name.substring(0, j);
            name = name.substring(j + 1);
            Class class1 = Class.forName(classRoot + /*"." + s1 +*/ "." + s2 + ".Protocol");
            ConnectionBaseInterface connectionbaseinterface = (ConnectionBaseInterface)class1.newInstance();
            return connectionbaseinterface.openPrim(name, mode, flag);
        }
        catch(InstantiationException instantiationexception)
        {
            throw new IOException(instantiationexception.toString());
        }
        catch(IllegalAccessException illegalaccessexception)
        {
            throw new IOException(illegalaccessexception.toString());
        }
        catch(ClassCastException classcastexception)
        {
            throw new IOException(classcastexception.toString());
        }
    }

    public static DataInputStream openDataInputStream(String name)
        throws IOException
    {
        InputConnection inputconnection = (InputConnection)open(name, READ);
        DataInputStream datainputstream = inputconnection.openDataInputStream();
        inputconnection.close();
        return datainputstream;
    }

    public static DataOutputStream openDataOutputStream(String name)
        throws IOException
    {
        OutputConnection outputconnection = (OutputConnection)open(name, WRITE);
        DataOutputStream dataoutputstream = outputconnection.openDataOutputStream();
        outputconnection.close();
        return dataoutputstream;
    }

    public static InputStream openInputStream(String name)
        throws IOException
    {
        return openDataInputStream(name);
    }

    public static OutputStream openOutputStream(String name)
        throws IOException
    {
        return openDataOutputStream(name);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -