Search in sources :

Example 86 with ParcelFileDescriptor

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);
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 87 with ParcelFileDescriptor

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) {
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 88 with ParcelFileDescriptor

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();
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with ParcelFileDescriptor

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();
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) LocalServerSocket(android.net.LocalServerSocket) LocalSocket(android.net.LocalSocket)

Example 90 with ParcelFileDescriptor

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();
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Aggregations

ParcelFileDescriptor (android.os.ParcelFileDescriptor)526 IOException (java.io.IOException)199 FileNotFoundException (java.io.FileNotFoundException)136 RemoteException (android.os.RemoteException)127 File (java.io.File)127 FileDescriptor (java.io.FileDescriptor)58 FileOutputStream (java.io.FileOutputStream)58 AssetFileDescriptor (android.content.res.AssetFileDescriptor)44 FileInputStream (java.io.FileInputStream)36 Parcel (android.os.Parcel)35 Uri (android.net.Uri)33 Intent (android.content.Intent)30 Bundle (android.os.Bundle)29 Cursor (android.database.Cursor)27 StorageManager (android.os.storage.StorageManager)25 Request (android.app.DownloadManager.Request)24 Bitmap (android.graphics.Bitmap)22 InputStream (java.io.InputStream)18 ProfilerInfo (android.app.ProfilerInfo)17 Binder (android.os.Binder)17