本文整理汇总了Java中java.io.FileInputStream.getFD方法的典型用法代码示例。如果您正苦于以下问题:Java FileInputStream.getFD方法的具体用法?Java FileInputStream.getFD怎么用?Java FileInputStream.getFD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.getFD方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadAndWrite
import java.io.FileInputStream; //导入方法依赖的package包/类
@Test(timeout=10000)
public void testReadAndWrite() throws Exception {
File path = new File(TEST_BASE, "testReadAndWrite");
path.mkdirs();
SharedFileDescriptorFactory factory =
SharedFileDescriptorFactory.create("woot_",
new String[] { path.getAbsolutePath() });
FileInputStream inStream =
factory.createDescriptor("testReadAndWrite", 4096);
FileOutputStream outStream = new FileOutputStream(inStream.getFD());
outStream.write(101);
inStream.getChannel().position(0);
Assert.assertEquals(101, inStream.read());
inStream.close();
outStream.close();
FileUtil.fullyDelete(path);
}
示例2: transfer
import java.io.FileInputStream; //导入方法依赖的package包/类
static public long transfer(long position, long count, FileInputStream src, FileOutputStream dst) throws IOException {
FileChannel srcChannel = src.getChannel();
FileChannel dstChannel = dst.getChannel();
if (!srcChannel.isOpen()) {
throw new ClosedChannelException();
}
if (!dstChannel.isOpen()) {
throw new ClosedChannelException();
}
if (position < 0 || count < 0) {
throw new IllegalArgumentException("position=" + position + " count=" + count);
}
if (count == 0 || position >= srcChannel.size()) {
return 0;
}
count = Math.min(count, srcChannel.size() - position);
FileDescriptor inFd = src.getFD();
FileDescriptor outFd = dst.getFD();
long rc = 0;
rc = native_sendfile_64(outFd, inFd, position, count);
return rc;
}
示例3: loadBitmapFromDiskCache
import java.io.FileInputStream; //导入方法依赖的package包/类
private Bitmap loadBitmapFromDiskCache(String url, int reqWidth, int reqHeight) throws IOException {
if (Looper.myLooper() == Looper.getMainLooper()) {
Log.w(TAG, "load bitmap from UI thread, it's not recommended!");
}
if (mDiskLruCache == null) {
return null;
}
Bitmap bitmap = null;
String key = hashKeyFormUrl(url);
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key);
if (snapshot != null) {
FileInputStream fileInputStream = (FileInputStream) snapshot.getInputStream(DISK_CACHE_INDEX);
FileDescriptor fileDescriptor = fileInputStream.getFD();
bitmap = ImageResizeUtil.decodeBitmapFromFileDescriptor(fileDescriptor, reqWidth, reqHeight);
if (bitmap != null) {
addBitmapToMemoryCache(key, bitmap);
}
}
return bitmap;
}
示例4: loadBitmapFromDiskCache
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* 在存储缓存中读取Bitmap
* @param url
* @param reqWidth
* @param reqHeight
* @return
* @throws IOException
*/
private Bitmap loadBitmapFromDiskCache(String url, int reqWidth, int reqHeight) throws IOException{
if(Looper.myLooper() == Looper.getMainLooper()){
throw new RuntimeException("can not visit network from UI Thread.");
}
if(mDiskLruCache == null){
return null;
}
Bitmap bitmap = null;
String key = hashKeyFromUrl(url);
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key);
if(snapshot != null){
FileInputStream fileInputStream = (FileInputStream) snapshot.getInputStream(DISK_CACHE_INDEX);
//文件描述
FileDescriptor fileDescriptor = fileInputStream.getFD();
bitmap = mImageResizer.decodeSampleeBitmapFromFileDescriptor(fileDescriptor,reqWidth,reqHeight);
if(bitmap != null){
//添加到内存缓存
addBitmapToMemoryCache(key,bitmap);
}
}
return bitmap;
}
示例5: setDataSource
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Sets the data source (file-path or http/rtsp URL) to use.
*
* @param path the path of the file, or the http/rtsp URL of the stream you want to play
* @param keys AVOption key
* @param values AVOption value
* @throws IllegalStateException if it is called in an invalid state
*/
public void setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
final Uri uri = Uri.parse(path);
if ("file".equals(uri.getScheme())) {
path = uri.getPath();
}
final File file = new File(path);
if (file.exists()) {
FileInputStream is = new FileInputStream(file);
FileDescriptor fd = is.getFD();
setDataSource(fd);
is.close();
} else {
_setDataSource(path, keys, values);
}
}