本文整理了Java中java.io.FileInputStream.getFD()
方法的一些代码示例,展示了FileInputStream.getFD()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileInputStream.getFD()
方法的具体详情如下:
包路径:java.io.FileInputStream
类名称:FileInputStream
方法名:getFD
[英]Returns the underlying file descriptor.
[中]返回基础文件描述符。
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public FileDescriptor getFileDescriptor() throws IOException {
return fis.getFD();
}
}
代码示例来源:origin: robolectric/robolectric
private static FileDescriptor open(String fname) {
try {
return new FileInputStream(new File(fname)).getFD();
} catch (IOException e) {
return null;
}
}
代码示例来源:origin: stackoverflow.com
FileInputStream fileInputStream = new FileInputStream("/data/data/com.mypackage/myfile");
mediaPlayer.setDataSource(fileInputStream.getFD());
代码示例来源:origin: stackoverflow.com
FileInputStream fileInputStream = new FileInputStream("/data/data/com.mypackage/myfile");
mediaPlayer.setDataSource(fileInputStream.getFD());
代码示例来源:origin: stackoverflow.com
FileInputStream fileInputStream = new FileInputStream(mFile);
mPlayer.setDataSource(fileInputStream.getFD());
fileInputStream.close();
mPlayer.prepare();
代码示例来源:origin: org.apache.hadoop/hadoop-common
@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;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@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;
}
}
代码示例来源:origin: stackoverflow.com
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();
}
}
代码示例来源:origin: stackoverflow.com
if(fs!=null) bm=BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions);
} catch (IOException e) {
代码示例来源:origin: voldemort/voldemort
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());
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
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;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* 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();
}
}
}
代码示例来源:origin: robolectric/robolectric
/**
* 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);
}
}
代码示例来源:origin: robolectric/robolectric
/**
* 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);
}
}
代码示例来源:origin: apache/geode
fd = ((FileInputStream) sockStream).getFD();
} catch (Exception e) {
sockStream = sock.getInputStream();
if (sockStream instanceof FileInputStream) {
fd = ((FileInputStream) sockStream).getFD();
代码示例来源:origin: androidquery/androidquery
FileDescriptor fd = fis.getFD();
result = BitmapFactory.decodeFileDescriptor(fd, null, options);
代码示例来源:origin: robolectric/robolectric
/**
* 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);
}
}
代码示例来源:origin: robolectric/robolectric
@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();
}
}
代码示例来源:origin: robolectric/robolectric
@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();
}
}
代码示例来源:origin: jline/jline
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;
}
内容来源于网络,如有侵权,请联系作者删除!