private ParcelFileDescriptor openReadInternal(String name) throws IOException { assertPreparedAndNotSealed("openRead"); try { if (!FileUtils.isValidExtFilename(name)) { throw new IllegalArgumentException("Invalid name: " + name); } final File target = new File(resolveStageDir(), name); final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0); return ParcelFileDescriptor.dup(targetFd); } catch (ErrnoException e) { throw new IOException(e); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation(maxSdk = M) public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation(maxSdk = M) public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will be * returned if the resource is found. If the resource cannot be found, {@link * Resources.NotFoundException} will be thrown. */ @Implementation protected AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } } else { return directlyOn(realResources, Resources.class).openRawResourceFd(id); } }
return ParcelFileDescriptor.dup(bridge.getClientSocket());
public ParcelFileDescriptor getInputMemoryFile() throws RemoteException { ParcelFileDescriptor pfd = null; try { pfd = ParcelFileDescriptor.dup(inputMemoryFileDiscriptor); } catch (IOException e) { Log.e(LOG_TAG, "Failed to dup input memory file descriptor"); } return pfd; }
private static Object marshallParamater(Class type,Object obj) { if (FileDescriptor.class.equals(type) && obj instanceof FileDescriptor) { try { return ParcelFileDescriptor.dup(((FileDescriptor) obj)); } catch (IOException e) { e.printStackTrace(); } } return obj; }
private ParcelFileDescriptor openReadInternal(String name) throws IOException { assertPreparedAndNotSealed("openRead"); try { if (!FileUtils.isValidExtFilename(name)) { throw new IllegalArgumentException("Invalid name: " + name); } final File target = new File(resolveStageDir(), name); final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0); return ParcelFileDescriptor.dup(targetFd); } catch (ErrnoException e) { throw new IOException(e); } }
private ParcelFileDescriptor openReadInternal(String name) throws IOException { assertPreparedAndNotSealed("openRead"); try { if (!FileUtils.isValidExtFilename(name)) { throw new IllegalArgumentException("Invalid name: " + name); } final File target = new File(resolveStageDir(), name); final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0); return ParcelFileDescriptor.dup(targetFd); } catch (ErrnoException e) { throw new IOException(e); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) { int native_fd = -1; try { Field f = fd.getClass().getDeclaredField("descriptor"); //NoSuchFieldException f.setAccessible(true); native_fd = f.getInt(fd); //IllegalAccessException } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } _setDataSourceFd(native_fd); } else { ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd); try { _setDataSourceFd(pfd.getFd()); } finally { pfd.close(); } } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) { int native_fd = -1; try { Field f = fd.getClass().getDeclaredField("descriptor"); //NoSuchFieldException f.setAccessible(true); native_fd = f.getInt(fd); //IllegalAccessException } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } _setDataSourceFd(native_fd); } else { ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd); try { _setDataSourceFd(pfd.getFd()); } finally { pfd.close(); } } }
@Implementation public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { try { FileInputStream fis = (FileInputStream)openRawResource(id); return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (Exception e) { return null; } }
@Implementation public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { try { FileInputStream fis = (FileInputStream)openRawResource(id); return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (Exception e) { return null; } }
@Implementation public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { try { FileInputStream fis = (FileInputStream)openRawResource(id); return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (Exception e) { return null; } }
ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd); try { _setDataSourceFd(pfd.getFd());
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation(maxSdk = M) public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation(maxSdk = M) public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will * be returned if the resource is found. If the resource cannot be found, {@link Resources.NotFoundException} will * be thrown. */ @Implementation public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will be * returned if the resource is found. If the resource cannot be found, {@link * Resources.NotFoundException} will be thrown. */ @Implementation protected AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } } else { return directlyOn(realResources, Resources.class).openRawResourceFd(id); } }