當前位置: 首頁>>代碼示例>>Java>>正文


Java FileDescriptor.valid方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ExtendedSocketOptions.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ExtendedSocketOptions.java

示例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();
            }
        }
    }
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:11,代碼來源:FileBridge.java

示例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);
}
 
開發者ID:RikkaApps,項目名稱:FontProvider,代碼行數:46,代碼來源:FontManager.java

示例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);
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:52,代碼來源:AvosMediaMetadataRetriever.java


注:本文中的java.io.FileDescriptor.valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。