use of android.os.ParcelFileDescriptor in project facebook-android-sdk by facebook.
the class ShareInternalUtility method newUploadStagingResourceWithImageRequest.
/**
* Creates a new Request configured to upload an image to create a staging resource. Staging
* resources allow you to post binary data such as images, in preparation for a post of an Open
* Graph object or action which references the image. The URI returned when uploading a staging
* resource may be passed as the image property for an Open Graph object or action.
*
* @param accessToken the access token to use, or null
* @param file the file containing the image to upload
* @param callback a callback that will be called when the request is completed to handle
* success or error conditions
* @return a Request that is ready to execute
* @throws FileNotFoundException
*/
public static GraphRequest newUploadStagingResourceWithImageRequest(AccessToken accessToken, File file, Callback callback) throws FileNotFoundException {
ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
GraphRequest.ParcelableResourceWithMimeType<ParcelFileDescriptor> resourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType<>(descriptor, "image/png");
Bundle parameters = new Bundle(1);
parameters.putParcelable(STAGING_PARAM, resourceWithMimeType);
return new GraphRequest(accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback);
}
use of android.os.ParcelFileDescriptor in project facebook-android-sdk by facebook.
the class FacebookContentProviderTest method testOpenFileWithBadPath.
@SuppressWarnings("unused")
@Test
public void testOpenFileWithBadPath() throws Exception {
try {
ParcelFileDescriptor pfd = providerUnderTest.openFile(Uri.parse("/"), "r");
fail("expected FileNotFoundException");
} catch (FileNotFoundException e) {
}
}
use of android.os.ParcelFileDescriptor in project facebook-android-sdk by facebook.
the class FacebookContentProviderTest method testOpenFileWithKnownUri.
@Test
public void testOpenFileWithKnownUri() throws Exception {
MockAttachmentStore.addAttachment(CALL_ID, ATTACHMENT_NAME);
ParcelFileDescriptor pfd = getTestAttachmentParcelFileDescriptor(CALL_ID);
assertNotNull(pfd);
pfd.close();
}
use of android.os.ParcelFileDescriptor in project fqrouter by fqrouter.
the class SocksVpnService method passTcpFileDescriptor.
private void passTcpFileDescriptor(LocalSocket fdSocket, OutputStream outputStream, String dstIp, int dstPort, int connectTimeout) throws Exception {
Socket sock = new Socket();
// force file descriptor being created
sock.setTcpNoDelay(true);
try {
ParcelFileDescriptor fd = ParcelFileDescriptor.fromSocket(sock);
if (protect(fd.getFd())) {
try {
sock.connect(new InetSocketAddress(dstIp, dstPort), connectTimeout);
try {
fdSocket.setFileDescriptorsForSend(new FileDescriptor[] { fd.getFileDescriptor() });
outputStream.write('*');
outputStream.flush();
} finally {
sock.close();
fd.close();
}
} catch (ConnectException e) {
LogUtils.e("connect " + dstIp + ":" + dstPort + " failed");
outputStream.write('!');
} catch (SocketTimeoutException e) {
LogUtils.e("connect " + dstIp + ":" + dstPort + " failed");
outputStream.write('!');
} finally {
outputStream.flush();
}
} else {
LogUtils.e("protect tcp socket failed");
}
} finally {
sock.close();
}
}
use of android.os.ParcelFileDescriptor in project fqrouter by fqrouter.
the class SocksVpnService method passUdpFileDescriptor.
private void passUdpFileDescriptor(LocalSocket fdSocket, OutputStream outputStream) throws Exception {
DatagramSocket sock = new DatagramSocket();
try {
ParcelFileDescriptor fd = ParcelFileDescriptor.fromDatagramSocket(sock);
if (protect(fd.getFd())) {
try {
fdSocket.setFileDescriptorsForSend(new FileDescriptor[] { fd.getFileDescriptor() });
outputStream.write('*');
outputStream.flush();
} finally {
sock.close();
fd.close();
}
} else {
LogUtils.e("protect udp socket failed");
}
} finally {
sock.close();
}
}
Aggregations