@Override public FileDescriptor getFileDescriptor() throws IOException { return fis.getFD(); } }
private static FileDescriptor open(String fname) { try { return new FileInputStream(new File(fname)).getFD(); } catch (IOException e) { return null; } }
FileInputStream fileInputStream = new FileInputStream("/data/data/com.mypackage/myfile"); mediaPlayer.setDataSource(fileInputStream.getFD());
FileInputStream fileInputStream = new FileInputStream("/data/data/com.mypackage/myfile"); mediaPlayer.setDataSource(fileInputStream.getFD());
FileInputStream fileInputStream = new FileInputStream(mFile); mPlayer.setDataSource(fileInputStream.getFD()); fileInputStream.close(); mPlayer.prepare();
@Override public FileDescriptor getFileDescriptor() throws IOException { if (in instanceof HasFileDescriptor) { return ((HasFileDescriptor) in).getFileDescriptor(); } else if (in instanceof FileInputStream) { return ((FileInputStream) in).getFD(); } else { return null; } }
@Override public FileDescriptor getFileDescriptor() throws IOException { if (in instanceof HasFileDescriptor) { return ((HasFileDescriptor) in).getFileDescriptor(); } else if (in instanceof FileInputStream) { return ((FileInputStream) in).getFD(); } else { return null; } }
private MediaPlayer mediaPlayer = new MediaPlayer(); private void playMp3(byte[] mp3SoundByteArray) { try { // create temp file that will hold byte array File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir()); tempMp3.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tempMp3); fos.write(mp3SoundByteArray); fos.close(); // resetting mediaplayer instance to evade problems mediaPlayer.reset(); // In case you run into issues with threading consider new instance like: // MediaPlayer mediaPlayer = new MediaPlayer(); // Tried passing path directly, but kept getting // "Prepare failed.: status=0x1" // so using file descriptor instead FileInputStream fis = new FileInputStream(tempMp3); mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.prepare(); mediaPlayer.start(); } catch (IOException ex) { String s = ex.toString(); ex.printStackTrace(); } }
if(fs!=null) bm=BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions); } catch (IOException e) {
public static void main(String[] args) throws Exception { String path = args[0]; File file = new File(path); FileInputStream in = new FileInputStream(file); int fd = voldemort.store.readonly.io.Native.getFd(in.getFD()); if(logger.isDebugEnabled()) logger.debug("File descriptor is: " + fd); // mmap a large file... Pointer addr = mmap(file.length(), PROT_READ, mman.MAP_SHARED, fd, 0L); if(logger.isDebugEnabled()) logger.debug("mmap address is: " + Pointer.nativeValue(addr)); // try to mlock it directly mlock(addr, file.length()); munlock(addr, file.length()); munmap(addr, file.length()); } }
private MediaExtractor getMediaExtractor(FileInputStream source, long offset, long length) throws IOException { MediaExtractor extractor = new MediaExtractor(); extractor.setDataSource(source.getFD(), offset, length); extractor.selectTrack(0); return extractor; } }
/** * Same as openForRead() except that it will run even if security is off. * This is used by unit tests. */ @VisibleForTesting protected static FileInputStream forceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) throws IOException { FileInputStream fis = new FileInputStream(f); boolean success = false; try { Stat stat = NativeIO.POSIX.getFstat(fis.getFD()); checkStat(f, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup); success = true; return fis; } finally { if (!success) { fis.close(); } } }
/** * 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); } }
FileDescriptor fd = fis.getFD(); result = BitmapFactory.decodeFileDescriptor(fd, null, options);
/** * 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); } }
@SuppressWarnings("ObjectToString") @Test public void decodeFileDescriptor_shouldGetWidthAndHeightFromHints() throws Exception { File tmpFile = File.createTempFile("BitmapFactoryTest", null); try { tmpFile.deleteOnExit(); try (FileInputStream is = new FileInputStream(tmpFile)) { FileDescriptor fd = is.getFD(); ShadowBitmapFactory.provideWidthAndHeightHints(fd, 123, 456); Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd); assertEquals("Bitmap for fd:" + fd, shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); } } finally { tmpFile.delete(); } }
@Test public void testSetDataSourceFD() throws IOException { File tmpFile = File.createTempFile("MediaPlayerTest", null); try { tmpFile.deleteOnExit(); FileInputStream is = new FileInputStream(tmpFile); try { FileDescriptor fd = is.getFD(); DataSource ds = toDataSource(fd, 23, 524); ShadowMediaPlayer.addMediaInfo(ds, info); mediaPlayer.setDataSource(fd, 23, 524); assertThat(shadowMediaPlayer.getSourceUri()).named("sourceUri").isNull(); assertThat(shadowMediaPlayer.getDataSource()).named("dataSource") .isEqualTo(ds); } finally { is.close(); } } finally { tmpFile.delete(); } }
protected boolean isSystemIn(final InputStream in) throws IOException { if (in == null) { return false; } else if (in == System.in) { return true; } else if (in instanceof FileInputStream && ((FileInputStream) in).getFD() == FileDescriptor.in) { return true; } return false; }