当前位置: 首页>>代码示例>>Java>>正文


Java Connector类代码示例

本文整理汇总了Java中javax.microedition.io.Connector的典型用法代码示例。如果您正苦于以下问题:Java Connector类的具体用法?Java Connector怎么用?Java Connector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Connector类属于javax.microedition.io包,在下文中一共展示了Connector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerTagListener

import javax.microedition.io.Connector; //导入依赖的package包/类
private PluginResult registerTagListener() throws NFCException, JSONException {
    ReaderWriterManager nfc = ReaderWriterManager.getInstance();

    tagListener  = new DetectionListener() {

        public void onTargetDetected(Target target) {

            Hashtable props = Util.getTagProperties(target);

            NDEFMessage message = null;
            try {
                NDEFTagConnection tagConnection = (NDEFTagConnection) Connector.open(target.getUri(Target.NDEF_TAG));
                message = tagConnection.read();  // might want to handle NFCException different
            } catch (IOException e) {
                Logger.error("Failed reading tag " + e.toString());
            }

            fireNdefEvent(TAG_DEFAULT, message, props);

        }
    };
    nfc.addDetectionListener(tagListener);
    return new PluginResult(Status.OK);
}
 
开发者ID:theGreatWhiteShark,项目名称:mensacard-hack,代码行数:25,代码来源:NfcPlugin.java

示例2: servicesDiscovered

import javax.microedition.io.Connector; //导入依赖的package包/类
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    if(servRecord!=null && servRecord.length>0){
        connectionURL = servRecord[0].getConnectionURL(0,false);
    }
    isOK = true;
    try {
        StreamConnection streamConnection = (StreamConnection) Connector.open(connectionURL);
        // send string
        OutputStream outStream = streamConnection.openOutputStream();
        out = new PrintWriter(new OutputStreamWriter(outStream));
        // read response
        InputStream inStream = streamConnection.openInputStream();
        in = new BufferedReader(new InputStreamReader(inStream));
        if(onConnectionSuccessful != null) onConnectionSuccessful.actionPerformed(new ActionEvent(this,ActionEvent.RESERVED_ID_MAX+1,""));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:arminkz,项目名称:BluetoothChat,代码行数:19,代码来源:SPPClient.java

示例3: load

import javax.microedition.io.Connector; //导入依赖的package包/类
/**
     * Loads an object memory from a given input stream. If the URI describing the source of the input
     * stream corresponds to the URI of an object memory already present in the system, then that object
     * memory is returned instead.
     *
     * @param uri                     a URI identifying the object memory being loaded
     * @param loadIntoReadOnlyMemory  specifies if the object memory should be put into read-only memory
     * @return the ObjectMemoryFile instance encapsulating the loaded/resolved object memory
     * @throws java.io.IOException 
     */
    public static ObjectMemoryFile load(String uri, boolean loadIntoReadOnlyMemory) throws IOException {
        String url;
/*if[ENABLE_HOSTED]*/	
        if (VM.isHosted()) {
            url = convertURIHosted(uri);
        } else
/*end[ENABLE_HOSTED]*/	    
	{
            url = uri;
        }
        if (url.startsWith("file://") && filePathelements != null) {
        	url += ";" + filePathelements;
        }
        try {
            DataInputStream dis = Connector.openDataInputStream(url);
            ObjectMemoryFile result = load(dis, uri, loadIntoReadOnlyMemory);
            dis.close();
            return result;
        } catch (ConnectionNotFoundException e) {
System.out.println("filePathelements=" + filePathelements);
            throw e;
        }
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:34,代码来源:ObjectMemoryLoader.java

示例4: installSectors

import javax.microedition.io.Connector; //导入依赖的package包/类
/**
 * Check to see if there are sectors already installed for the purpose
 * specified, or If there are sectors found on file system use them as is,
 * if not then setup with number of sectors and sectorSize as specified
 */
public void installSectors(int numberOfSectors, int sectorSize, int purpose) {
    if (sectors.size() > 0) {
        int a=1;
    }
    boolean foundSome = false;
    final String sectorsFileExtension = SimulatedNorFlashSector.SECTORS_FILE_EXTENSION;
    try {
        DataInputStream fileListInput = Connector.openDataInputStream("file://./");
        while (fileListInput.available() > 0) {
            String fileName = fileListInput.readUTF();
            if (fileName.endsWith(sectorsFileExtension)) {
                foundSome = true;
                SimulatedNorFlashSector memorySector = new SimulatedNorFlashSector(fileName);
                releaseSector(memorySector, purpose);
            }
        }
        fileListInput.close();
    } catch (IOException e) {
        throw new UnexpectedException(e);
    }
    if (!foundSome) {
        setupSectors(numberOfSectors, sectorSize, purpose, true);
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:30,代码来源:SimulatedNorFlashSectorAllocator.java

示例5: setBytes

import javax.microedition.io.Connector; //导入依赖的package包/类
public void setBytes(int memoryOffset, byte[] buffer, int bufferOffset, int length) {
    if (length == 0) {
        return;
    }
    if ((memoryOffset & 1) == 1) {
        throw new IndexOutOfBoundsException("offset must be even");
    }
    if ((length & 1) == 1) {
        throw new IndexOutOfBoundsException("length must be even");
    }
    ensureInBounds(memoryOffset, buffer, bufferOffset, length);
    System.arraycopy(buffer, bufferOffset, bytes, memoryOffset, length);
    if (fileName == null) {
        return;
    }
    try {
        DataOutputStream output = Connector.openDataOutputStream("file://" + fileName);
        output.writeInt(startAddress.toUWord().toInt());
        output.writeInt(size);
        output.writeShort(purpose);
        output.write(bytes);
        output.close();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:27,代码来源:SimulatedNorFlashSector.java

示例6: main

import javax.microedition.io.Connector; //导入依赖的package包/类
public static void main(String[] args) {
    // Default to indicate error
    int returnCode = -1;
    try {
        StreamConnection connection = (StreamConnection) Connector.open("uei:");
        DataOutputStream out = connection.openDataOutputStream();
        out.writeInt(args.length);
        for (int i=0; i < args.length; i++) {
            out.writeUTF(args[i]);
        }
        out.close();
        InputStream in = connection.openInputStream();
        returnCode = in.read();
        in.close();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        System.exit(returnCode);
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:21,代码来源:Launcher.java

示例7: open

import javax.microedition.io.Connector; //导入依赖的package包/类
public Connection open(String protocol, String url, int mode, boolean timeouts) throws IOException {
    
    if(protocol == null || protocol.length()==0){
        throw new IllegalArgumentException("Protocol cannot be null or empty");
    }
    
    if (mode != Connector.READ && mode != Connector.WRITE && mode != Connector.READ_WRITE) {
        throw new IllegalArgumentException("illegal mode: " + mode);
    }
    
    if (opened) {
        throw new IOException("already connected");
    }
    
    this.url = url;
    this.mode = mode;
    this.timeouts = timeouts;
    parseURL();
    opened=true;
    opens++;
    return this;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:23,代码来源:Protocol.java

示例8: openInputStream

import javax.microedition.io.Connector; //导入依赖的package包/类
public InputStream openInputStream() throws IOException {

        if (in != null) {
            throw new IOException("already open");
        }

        // If the connection was opened and closed before the
        // data input stream is accessed, throw an IO exception
        if (!opened) {
            throw new IOException("connection is closed");
        }

        // Check that the connection was opened for reading
        if (mode != Connector.READ && mode != Connector.READ_WRITE) {
            throw new IOException("write-only connection");
        }

        connect();
        opens++;
        in = new PrivateInputStream();
        return in;
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:23,代码来源:Protocol.java

示例9: openOutputStream

import javax.microedition.io.Connector; //导入依赖的package包/类
public OutputStream openOutputStream() throws IOException {

        if (mode != Connector.WRITE && mode != Connector.READ_WRITE) {
            throw new IOException("read-only connection");
        }

        // If the connection was opened and closed before the
        // data output stream is accessed, throw an IO exception
        if (!opened) {
            throw new IOException("connection is closed");
        }

        if (out != null) {
            throw new IOException("already open");
        }

        opens++;
        out = new PrivateOutputStream();
        return out;
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:21,代码来源:Protocol.java

示例10: getInvokeContext

import javax.microedition.io.Connector; //导入依赖的package包/类
protected Object getInvokeContext() throws IOException {
    HttpConnection conn = (HttpConnection)Connector.open(uri, Connector.READ_WRITE);
    if (keepAlive) {
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setRequestProperty("Keep-Alive", Integer.toString(keepAliveTimeout));
    }
    else {
        conn.setRequestProperty("Connection", "Close");
    }
    conn.setRequestProperty("Cookie", cookieManager.getCookie(conn.getHost(),
                                                              conn.getFile(),
                                                              conn.getProtocol().equals("https")));
    for (Enumeration e = headers.keys(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        conn.setRequestProperty(key, (String) headers.get(key));
    }
    return conn;
}
 
开发者ID:hprose,项目名称:hprose-j2me,代码行数:19,代码来源:HproseHttpClient.java

示例11: getInvokeContext

import javax.microedition.io.Connector; //导入依赖的package包/类
protected Object getInvokeContext() throws IOException {
    HttpConnection conn = (HttpConnection)Connector.open(uri, Connector.READ_WRITE);
    if (keepAlive) {
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setRequestProperty("Keep-Alive", Integer.toString(keepAliveTimeout));
    }
    else {
        conn.setRequestProperty("Connection", "Close");
    }
    conn.setRequestProperty("Cookie", cookieManager.getCookie(conn.getHost(),
                                                              conn.getFile(),
                                                              conn.getProtocol().equals("https")));
    for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
        Entry entry = (Entry) iter.next();
        conn.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
    }
    return conn;
}
 
开发者ID:hprose,项目名称:hprose-j2me,代码行数:19,代码来源:HproseHttpClient.java

示例12: PAKBluetoothPairingHandler

import javax.microedition.io.Connector; //导入依赖的package包/类
public PAKBluetoothPairingHandler(String password, String eMail,
		String firstName, String lastName, String deviceName,
		X509Certificate ownerCertEnc, X509Certificate ownerCertSign,
		Map<String, X509Certificate> knownDevices,
		Collection<VCard> knownContacts) throws IOException {
	super(PairingType.SLAVE, password, eMail, firstName, lastName,
			deviceName, ownerCertEnc, ownerCertSign, knownDevices,
			knownContacts);
	UUID uuid = new UUID(0x1101); // TODO: Create new unique UUID
	String connectionString = "btspp://localhost:" + uuid
			+ ";name=PanboxImportListener;encrypt=false;authenticate=false";
	streamConnNotifier = (StreamConnectionNotifier) Connector.open(
			connectionString, Connector.READ_WRITE);
	ServiceRecord record = LocalDevice.getLocalDevice().getRecord(
			streamConnNotifier);
	logger.debug("PAKBluetoothPairingHandler : connection is up at: "
			+ record.getConnectionURL(0, false));
}
 
开发者ID:Rohde-Schwarz-Cybersecurity,项目名称:PanBox,代码行数:19,代码来源:PAKBluetoothPairingHandler.java

示例13: test0001

import javax.microedition.io.Connector; //导入依赖的package包/类
/**
 * Tests canRead() on a readable file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Setting file as readable");
			conn.setReadable(true);
			
			boolean canRead = conn.canRead();
			addOperationDesc("canRead() returned " + canRead);
			
			passed = canRead==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canRead() on a readable file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:CanRead.java

示例14: test0001

import javax.microedition.io.Connector; //导入依赖的package包/类
/**
 * create() creates a new file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Deleting file: " + conn.getURL());
			ensureNotExists(conn);
			
			addOperationDesc("Creating file");
			conn.create();

			boolean exists = conn.exists();
			addOperationDesc("exists() returned " + exists);
			
			passed = exists==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("create() creates a new file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:Create.java

示例15: displayAndCalculate

import javax.microedition.io.Connector; //导入依赖的package包/类
public void displayAndCalculate() {
    try {
        Display.getDisplay(this).setCurrent(form);
        FileConnection fileConnection = (FileConnection) Connector.open(textFieldSampleUrl.getString(), Connector.READ);
        InputStream inputStream = fileConnection.openInputStream();
        FileReader fileReader = new FileReader(inputStream);
        String totalString = "";
        Vector lines = fileReader.readLines();
        for (int i = 0; i < lines.size(); i++) {
            String line = (String)lines.elementAt(i);
            totalString += line + "\r\n";
        }
        stringItemStatus.setText(totalString);
    } catch (IOException e) {
    }
}
 
开发者ID:kamcpp,项目名称:heart-diag-app,代码行数:17,代码来源:HeartDiagAppMidlet.java


注:本文中的javax.microedition.io.Connector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。