本文整理汇总了Java中org.robovm.apple.foundation.NSData类的典型用法代码示例。如果您正苦于以下问题:Java NSData类的具体用法?Java NSData怎么用?Java NSData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NSData类属于org.robovm.apple.foundation包,在下文中一共展示了NSData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
@Override protected RFuture<Response> execute(Builder req) {
RPromise<Response> result = plat.exec().deferredPromise();
NSMutableURLRequest mreq = new NSMutableURLRequest();
mreq.setURL(new NSURL(req.url));
for (Header header : req.headers) {
mreq.setHTTPHeaderField(header.name, header.value);
}
mreq.setHTTPMethod(req.method());
if (req.isPost()) {
mreq.setHTTPHeaderField("Content-type", req.contentType());
if (req.payloadString != null) {
try {
mreq.setHTTPBody(new NSData(req.payloadString.getBytes("UTF-8")));
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
}
} else {
mreq.setHTTPBody(new NSData(req.payloadBytes));
}
}
sendRequest(mreq, result);
return result;
}
示例2: getRemoteImage
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
@Override public Image getRemoteImage(final String url, int width, int height) {
final ImageImpl image = createImage(true, width, height, url);
plat.net().req(url).execute().
onSuccess(new Slot<Net.Response>() {
public void onEmit (Net.Response rsp) {
try {
image.succeed(toData(Scale.ONE, new UIImage(new NSData(rsp.payload()))));
} catch (Throwable t) {
plat.log().warn("Failed to decode remote image [url=" + url + "]", t);
image.fail(t);
}
}
}).
onFailure(new Slot<Throwable>() {
public void onEmit (Throwable cause) { image.fail(cause); }
});
return image;
}
示例3: create
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public static Drawable create(NSData data) {
Drawable drawable = null;
if(data == null)
return null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
byte[] bytes = data.getBytes();
if(bytes != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
try {
DocumentBuilder db = factory.newDocumentBuilder();
InputSource inputSource = new InputSource(inputStream);
Document document = db.parse(inputSource);
drawable = create(document.getDocumentElement());
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
}
return drawable;
}
示例4: create
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public static ResourceStateList create(NSData data, ResourceStateList resourceStateList) {
if(data == null)
return null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
byte[] bytes = data.getBytes();
if(bytes != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
try {
DocumentBuilder db = factory.newDocumentBuilder();
InputSource inputSource = new InputSource(inputStream);
Document document = db.parse(inputSource);
resourceStateList = inflateDocument(document, resourceStateList);
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
}
return resourceStateList;
}
示例5: getXML
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public static Document getXML(NSData nsData) {
Document document = null;
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
byte[] bytes = nsData.getBytes();
if(bytes != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
try {
DocumentBuilder db = dfactory.newDocumentBuilder();
InputSource inputSource = new InputSource(inputStream);
document = db.parse(inputSource);
} catch (SAXException | ParserConfigurationException | IOException e) {
e.printStackTrace();
}
}
return document;
}
示例6: setContentOfCell
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public static UITableViewCell setContentOfCell(String name, NSURL url, String adresse, String email) {
UITableViewCell cell = new UITableViewCell(new CGRect(0, 0, 300, 60));
UIImageView img = new UIImageView(new CGRect(20, 10, 70, 70));
NSData data = (NSData)NSData.read(url);
img.setImage(new UIImage(data));
cell.getContentView().addSubview(img);
UILabel label1 = new UILabel(new CGRect(100, 10, cell.getContentView().getFrame().getWidth(), 20));
label1.setText(name);
label1.setTextColor(UIColor.colorBrown());
cell.getContentView().addSubview(label1);
UILabel label2 = new UILabel(new CGRect(100, 35, cell.getContentView().getFrame().getWidth(), 20));
label2.setText(adresse);
cell.getContentView().addSubview(label2);
UILabel label3 = new UILabel(new CGRect(100, 55, cell.getContentView().getFrame().getWidth(), 20));
label3.setText(email);
cell.getContentView().addSubview(label3);
return cell;
}
示例7: didReceiveDeepLink
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
@Override
public void didReceiveDeepLink(GPPDeepLink deepLink) {
String deepLinkID = deepLink.getDeepLinkID();
NSData decodedData = GTLBase64.decodeWebSafe(deepLinkID);
if (decodedData == null)
return;
try {
deepLinkParams = (NSDictionary<?, ?>) NSJSONSerialization.createJSONObject(decodedData,
NSJSONReadingOptions.None);
Log.d("Deep link ID is %s", deepLinkID);
Log.d("This is my dictionary %s", deepLinkParams);
} catch (NSErrorException e) {
e.printStackTrace();
}
if (challengeReceivedHandler != null) {
challengeReceivedHandler.run();
}
}
示例8: setFile
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public void setFile(PFFile file) {
final String requestURL = file.getUrl(); // Save copy of url locally
url = file.getUrl(); // Save copy of url on the instance
file.getDataInBackground(new PFGetDataCallback() {
@Override
public void done(NSData data, NSError error) {
if (error == null) {
UIImage image = new UIImage(data);
if (requestURL.equals(url)) {
setImage(image);
setNeedsDisplay();
}
} else {
Log.e("Error on fetching file: %s", error);
}
}
});
}
示例9: onClick
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
@Override
public void onClick(UIBarButtonItem barButtonItem) {
if (photo.getPicture().isDataAvailable()) {
showShareSheet();
} else {
// [MBProgressHUD showHUDAddedTo:self.view animated:YES]; TODO
photo.getPicture().getDataInBackground(new PFGetDataCallback() {
@Override
public void done(NSData data, NSError error) {
// [MBProgressHUD hideHUDForView:self.view animated:YES]; TODO
if (error == null) {
showShareSheet();
}
}
});
}
}
示例10: didRegisterForRemoteNotifications
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
/**
* Will be called when the user accepted remote notifications and whenever
* the device token changes.
*
* @param application
* @param deviceToken will be used to identify this device from remote push
* notification servers.
*/
@Override
public void didRegisterForRemoteNotifications(UIApplication application, NSData deviceToken) {
if (deviceToken != null) {
/*
* **IMPORTANT** Normally you would send the deviceToken to a push
* notification server to be able to send push notifications to this
* device.
*/
// Let's store the device token in the app preferences.
NSUserDefaults.getStandardUserDefaults().put(DEVICE_TOKEN_USER_PREF, deviceToken);
NSUserDefaults.getStandardUserDefaults().synchronize();
}
// Call the success callback.
if (notificationRegistrationListener != null) {
notificationRegistrationListener.onSuccess();
notificationRegistrationListener = null;
}
}
示例11: displayMailComposerSheet
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
/**
* Displays an email composition interface inside the application. Populates
* all the Mail fields.
*/
private void displayMailComposerSheet() {
MFMailComposeViewController picker = new MFMailComposeViewController();
picker.setMailComposeDelegate(this);
picker.setSubject("Hello from California!");
// Set up recipients
picker.setToRecipients(Arrays.asList("[email protected]"));
picker.setCcRecipients(Arrays.asList("[email protected]", "[email protected]"));
picker.setBccRecipients(Arrays.asList("[email protected]"));
// Attach an image to the email
String path = NSBundle.getMainBundle().findResourcePath("rainy", "jpg");
NSData myData = NSData.read(new File(path));
picker.addAttachmentData(myData, "image/jpeg", "rainy");
// Fill out the email body text
String emailBody = "It is raining in sunny California!";
picker.setMessageBody(emailBody, false);
presentViewController(picker, true, null);
}
示例12: load
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public static void load(File path, int bufferId) {
NSData data = null;
try {
// mmap (if possible) the audio file for efficient reading/uploading
data = NSData.read(path, RoboAssets.READ_OPTS);
load(data.asByteBuffer(), path.getName(), bufferId);
} catch (NSErrorException e) {
throw new RuntimeException(e.toString());
} finally {
// now dispose the mmap'd file to free up resources
if (data != null) {
data.dispose();
}
}
}
示例13: getBytesSync
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
@Override
public ByteBuffer getBytesSync(String path) throws Exception {
File fullPath = resolvePath(path);
plat.log().debug("Loading bytes " + fullPath);
// this NSData will release resources when garbage collected
return NSData.read(fullPath, READ_OPTS).asByteBuffer();
}
示例14: getXML
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public Document getXML(NSURL url) throws IOException {
Document document = null;
NSData nsData = (NSData) cache.get(url.getAbsoluteString());
try {
if(nsData == null) { // trying to fetch (does not exist in cache)
nsData = NSData.read(url);
if(nsData == null) {
if(url.isFileURL())
throw new FileNotFoundException(url.getAbsoluteString());
} else {
cache.put(url.getAbsoluteString(), nsData);
}
}
if(nsData != null) {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
byte[] bytes = nsData.getBytes();
if(bytes != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
DocumentBuilder db = dfactory.newDocumentBuilder();
InputSource inputSource = new InputSource(inputStream);
document = db.parse(inputSource);
}
}
} catch (SAXException | ParserConfigurationException e) {
e.printStackTrace();
}
return document;
}
示例15: setContentOfCell
import org.robovm.apple.foundation.NSData; //导入依赖的package包/类
public void setContentOfCell(UITableViewCell cell, String txt, NSURL url) {
UIImageView img = new UIImageView(new CGRect(25, 5, 80, 80));
NSData data = (NSData) NSData.read(url);
img.setImage(new UIImage(data));
cell.getContentView().addSubview(img);
UILabel label = new UILabel(new CGRect(120, 30, cell.getContentView()
.getFrame().getWidth(), 20));
label.setText(txt);
cell.getContentView().addSubview(label);
}