本文整理汇总了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);
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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);
}
示例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();
}
}
示例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) {
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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);
}