當前位置: 首頁>>代碼示例>>Java>>正文


Java Connector.open方法代碼示例

本文整理匯總了Java中javax.microedition.io.Connector.open方法的典型用法代碼示例。如果您正苦於以下問題:Java Connector.open方法的具體用法?Java Connector.open怎麽用?Java Connector.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.microedition.io.Connector的用法示例。


在下文中一共展示了Connector.open方法的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: 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

示例4: 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

示例5: 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

示例6: PAKBluetoothPairingHandler

import javax.microedition.io.Connector; //導入方法依賴的package包/類
public PAKBluetoothPairingHandler(String password, String eMail,
		String firstName, String lastName, String deviceName,
		char[] keyPassword, PrivateKey ownerKeyEnc,
		PrivateKey ownerKeySign, Map<String, X509Certificate> knownDevices,
		Collection<VCard> knownContacts) throws IOException {
	super(PairingType.MASTER, password, eMail, firstName, lastName,
			deviceName, keyPassword, ownerKeyEnc, ownerKeySign,
			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

示例7: urlToStream

import javax.microedition.io.Connector; //導入方法依賴的package包/類
/**
 * Reads the content from the specified HTTP URL and returns InputStream
 * where the contents are read.
 * 
 * @return InputStream
 * @throws IOException
 */
private InputStream urlToStream(String url) throws IOException {
    // Open connection to the http url...
    HttpConnection connection = (HttpConnection) Connector.open(url);
    DataInputStream dataIn = connection.openDataInputStream();
    byte[] buffer = new byte[1000];
    int read = -1;
    // Read the content from url.
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();
    while ((read = dataIn.read(buffer)) >= 0) {
        byteout.write(buffer, 0, read);
    }
    dataIn.close();
    connection.close();
    // Fill InputStream to return with content read from the URL.
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout.toByteArray());
    return byteIn;
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:25,代碼來源:VideoCanvas.java

示例8: test0001

import javax.microedition.io.Connector; //導入方法依賴的package包/類
/**
 * Tests fileSize() on a file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE); 
		try {				
			addOperationDesc("Creating file with a size of 64 bytes: " + conn.getURL());
			ensureFileExists(conn);
			ensureFileSize(conn, 64);
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
			
			passed = fileSize==64;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests fileSize() on a file", passed);
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:27,代碼來源:FileSize.java

示例9: submitBug

import javax.microedition.io.Connector; //導入方法依賴的package包/類
public static void submitBug(Location location, String text, String user) {
    String url = API_URL + "addPOIexec?lat=" + location.getY() + "&lon=" + location.getX()
            + "&text=" + urlEncode(text) + "&format=js";
    try {
        HttpConnection httpConn = (HttpConnection) Connector.open(url);
        ByteArrayOutputStream reply = new ByteArrayOutputStream();
        InputStream in = httpConn.openDataInputStream();
        for (int b = in.read(); b != -1; b = in.read()) {
            reply.write(b);
        }
        in.close();
        System.out.println("OpenStreetBugs reply: " + reply.toString());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:cli,項目名稱:worldmap-classic,代碼行數:17,代碼來源:OpenStreetBugs.java

示例10: 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();
        currentSignal = SignalFactory.fromStream(inputStream);
        ((SimpleSignal) currentSignal).calculateMaxAltitude();
        ((SimpleSignal) currentSignal).calculateHighPoints();
        PanAndTimpkins panAndTimpkins = new PanAndTimpkins();
        panAndTimpkins.analyze(currentSignal);
        String diseaseName;
        if (panAndTimpkins.getDistanceTimeAverage() < 0.6) {
            diseaseName = "Sinus Tachycardia";
        } else if (panAndTimpkins.getDistanceTimeAverage() > 1.0) {
            diseaseName = "Sinus Bradicardia";
        } else if (panAndTimpkins.getDistanceTimeAverage() >= 0.6 && panAndTimpkins.getDistanceTimeAverage() <= 1.0) {
            diseaseName = "HEALTHY - No Disease!";
        } else {
            diseaseName = "Atrial Fibrillation";
        }
        stringItemStatus.setText("Disease: " + diseaseName);
        signalItem.setSignal(currentSignal);
    } catch (IOException e) {
    }
}
 
開發者ID:kamcpp,項目名稱:heart-diag-app,代碼行數:26,代碼來源:HeartDiagAppMidlet.java

示例11: test0012

import javax.microedition.io.Connector; //導入方法依賴的package包/類
/**
 * Tests isHidden() on a non-existent directory
 */
public void test0012() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Deleting directory: " + conn.getURL());
			ensureNotExists(conn);
			
			boolean isHidden = conn.isHidden();
			addOperationDesc("isHidden() returned " + isHidden);
			
			passed = isHidden==false;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("isHidden() returns false for a non-existent directory", passed);
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:26,代碼來源:IsHidden.java

示例12: run

import javax.microedition.io.Connector; //導入方法依賴的package包/類
public void run() {
    try {
        StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open("socket://:" + port);

        Client currentClient = null;

        while (true) {
            StreamConnection connection = server.acceptAndOpen();
            System.out.println("Client Connected.");

            if (currentClient != null) {
                currentClient.kill();
            }

            currentClient = new Client(connection);
            currentClient.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:runnymederobotics,項目名稱:robot2014,代碼行數:22,代碼來源:RobotServer.java

示例13: benchmarkLargeRead

import javax.microedition.io.Connector; //導入方法依賴的package包/類
void benchmarkLargeRead() throws IOException {
  SocketConnection client = (SocketConnection)Connector.open("socket://localhost:8000");

  OutputStream os = client.openOutputStream();
  os.write(("GET /bench/benchmark.jar HTTP/1.1\r\n" +
            "Host: localhost\r\n" +
            "Connection: close\r\n" +
            "\r\n").getBytes());
  os.close();

  InputStream is = client.openInputStream();
  byte[] data = new byte[1024];
  int len;
  long start = JVM.monotonicTimeMillis();
  do {
    len = is.read(data);
  } while (len != -1);
  System.out.println("large read time: " + (JVM.monotonicTimeMillis() - start));
  is.close();

  client.close();
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:23,代碼來源:SocketStressBench.java

示例14: test0005

import javax.microedition.io.Connector; //導入方法依賴的package包/類
/**
 * Tests canRead() on a file (readable attribute is NOT supported by filesystem)
 */
public void test0005() {
	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 non-readable");
			conn.setReadable(false);
			
			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 file (readable attribute is NOT supported by filesystem)", passed);
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:29,代碼來源:CanRead.java

示例15: test0004

import javax.microedition.io.Connector; //導入方法依賴的package包/類
/**
 * Tests canWrite() on a non-writable directory
 */
public void test0004() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating directory: " + conn.getURL());
			ensureDirExists(conn);
			
			addOperationDesc("Setting directory as non-writable");
			conn.setWritable(false);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==false;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a on-writable directory", passed);
}
 
開發者ID:mozilla,項目名稱:pluotsorbet,代碼行數:29,代碼來源:CanWrite.java


注:本文中的javax.microedition.io.Connector.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。