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 glide by bumptech.
the class GlideTest method mockUri.
private String mockUri(Uri uri, InputStream is) {
if (is == null) {
is = new ByteArrayInputStream(new byte[0]);
}
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
ShadowFileDescriptorContentResolver shadowContentResolver = (ShadowFileDescriptorContentResolver) ShadowExtractor.extract(contentResolver);
shadowContentResolver.registerInputStream(uri, is);
AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
shadowContentResolver.registerAssetFileDescriptor(uri, assetFileDescriptor);
return uri.toString();
}
use of android.os.ParcelFileDescriptor in project glide by bumptech.
the class FileDescriptorLocalUriFetcherTest method testLoadResource_returnsFileDescriptor.
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
Context context = RuntimeEnvironment.application;
Uri uri = Uri.parse("file://nothing");
ContentResolver contentResolver = context.getContentResolver();
ContentResolverShadow shadow = (ContentResolverShadow) ShadowExtractor.extract(contentResolver);
AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
shadow.registerFileDescriptor(uri, assetFileDescriptor);
FileDescriptorLocalUriFetcher fetcher = new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
fetcher.loadData(Priority.NORMAL, callback);
verify(callback).onDataReady(eq(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();
}
}
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