本文整理汇总了Java中java.io.FileDescriptor.valid方法的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptor.valid方法的具体用法?Java FileDescriptor.valid怎么用?Java FileDescriptor.valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileDescriptor
的用法示例。
在下文中一共展示了FileDescriptor.valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setOption
import java.io.FileDescriptor; //导入方法依赖的package包/类
@Override
public void setOption(FileDescriptor fd,
SocketOption<?> option,
Object value)
throws SocketException
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new NetworkPermission("setOption." + option.name()));
if (fd == null || !fd.valid())
throw new SocketException("socket closed");
if (option == SO_FLOW_SLA) {
assert flowSupported;
SocketFlow flow = checkValueType(value, option.type());
setFlowOption(fd, flow);
} else {
throw new InternalError("Unexpected option " + option);
}
}
示例2: getOption
import java.io.FileDescriptor; //导入方法依赖的package包/类
@Override
public Object getOption(FileDescriptor fd,
SocketOption<?> option)
throws SocketException
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new NetworkPermission("getOption." + option.name()));
if (fd == null || !fd.valid())
throw new SocketException("socket closed");
if (option == SO_FLOW_SLA) {
assert flowSupported;
SocketFlow flow = SocketFlow.create();
getFlowOption(fd, flow);
return flow;
} else {
throw new InternalError("Unexpected option " + option);
}
}
示例3: closeQuietly
import java.io.FileDescriptor; //导入方法依赖的package包/类
public static void closeQuietly(FileDescriptor fd) {
if (fd != null && fd.valid()) {
try {
Os.close(fd);
} catch (ErrnoException e) {
e.printStackTrace();
}
}
}
示例4: getFileDescriptor
import java.io.FileDescriptor; //导入方法依赖的package包/类
public static FileDescriptor getFileDescriptor(Context context, String filename) {
MemoryFile mf = sCache.get(filename);
if (mf != null) {
Log.i(TAG, "MemoryFile " + filename + " is in the cache");
FileDescriptor fd = MemoryFileUtils.getFileDescriptor(mf);
if (fd != null && fd.valid()) {
return fd;
} else {
Log.i(TAG, "MemoryFile " + filename + " is not valid?");
}
}
long time = System.currentTimeMillis();
Log.i(TAG, "loading file " + filename);
// built in font? read from asset
if (BUILT_IN_FONTS_SIZE.containsKey(filename)) {
mf = MemoryFileUtils.fromAsset(context.getAssets(), filename, FILE_SIZE.get(filename));
}
// downloadable font? read from file
if (mf == null) {
File file = ContextUtils.getExternalFile(context, filename);
if (file.exists()) {
mf = MemoryFileUtils.fromFile(file);
if (mf != null) {
FILE_SIZE.put(filename, mf.length());
}
}
}
// file not exist?
if (mf == null) {
Log.w(TAG, "loading " + filename + " failed");
return null;
}
Log.i(TAG, "loading finished in " + (System.currentTimeMillis() - time) + "ms");
sCache.put(filename, mf);
return MemoryFileUtils.getFileDescriptor(mf);
}
示例5: setDataSource
import java.io.FileDescriptor; //导入方法依赖的package包/类
public void setDataSource(Context context, Uri uri)
throws IllegalArgumentException, SecurityException {
if (uri == null) {
throw new IllegalArgumentException();
}
String scheme = uri.getScheme();
if (SmbProxy.needToStream(scheme)){
mSmbProxy = SmbProxy.setDataSource(uri, this, null);
return;
}
if(scheme == null || scheme.equals("file")) {
setDataSource(uri.getPath());
return;
}
AssetFileDescriptor fd = null;
try {
ContentResolver resolver = context.getContentResolver();
try {
fd = resolver.openAssetFileDescriptor(uri, "r");
} catch(FileNotFoundException e) {
throw new IllegalArgumentException();
}
if (fd == null) {
throw new IllegalArgumentException();
}
FileDescriptor descriptor = fd.getFileDescriptor();
if (!descriptor.valid()) {
throw new IllegalArgumentException();
}
// Note: using getDeclaredLength so that our behavior is the same
// as previous versions when the content provider is returning
// a full file.
if (fd.getDeclaredLength() < 0) {
setDataSource(descriptor);
} else {
setDataSource(descriptor, fd.getStartOffset(), fd.getDeclaredLength());
}
return;
} catch (SecurityException ex) {
} finally {
try {
if (fd != null) {
fd.close();
}
} catch(IOException ioEx) {
}
}
setDataSource(uri.toString(), null, null);
}