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


Java PrivilegedActionException.toString方法代碼示例

本文整理匯總了Java中java.security.PrivilegedActionException.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java PrivilegedActionException.toString方法的具體用法?Java PrivilegedActionException.toString怎麽用?Java PrivilegedActionException.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.PrivilegedActionException的用法示例。


在下文中一共展示了PrivilegedActionException.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getURL

import java.security.PrivilegedActionException; //導入方法依賴的package包/類
/**
 * Gets URL with nbfs protocol for passes fo
 * @param fo
 * @return url with nbfs protocol
 */
static URL getURL(final FileObject fo) {
    String fsPart;
    try {
        fsPart = encodeFsPart(fo);
    } catch (FileStateInvalidException x) {
        fsPart = "invalid";
    }
    final String foPart = encodeFoPart(fo);

    final String host = "nbhost"; //NOI18N
    final String file = combine(fsPart, foPart);

    // #13038: the URL constructor accepting a handler is a security-sensitive
    // operation. Sometimes a user class loaded internally (customized bean...),
    // which has no privileges, needs to make and use an nbfs: URL, since this
    // may be the URL used by e.g. ClassLoader.getResource for resources.
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<URL>() {
                public URL run() throws Exception {
                    // #30397: the fsPart name cannot be null
                    return new URL(FileURL.PROTOCOL, host, -1, file, new FileURL.Handler());
                }
            }
        );
    } catch (PrivilegedActionException pae) {
        // MalformedURLException is declared but should not happen.
        IllegalStateException ise = new IllegalStateException(pae.toString());
        ExternalUtil.annotate(ise, pae);
        throw ise;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:NbfsUtil.java

示例2: readFile

import java.security.PrivilegedActionException; //導入方法依賴的package包/類
protected byte[] readFile(final String datafile)
    throws IOException, MissingResourceException {

    BufferedInputStream is;
    try {
        is = AccessController.doPrivileged(
            new PrivilegedExceptionAction<BufferedInputStream>() {
                @Override
                public BufferedInputStream run() throws Exception {
                    return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile));
                }
            }
        );
    }
    catch (PrivilegedActionException e) {
        throw new InternalError(e.toString(), e);
    }

    int offset = 0;

    /* First, read magic, version, and header_info. */
    int len = LABEL_LENGTH + 5;
    byte[] buf = new byte[len];
    if (is.read(buf) != len) {
        throw new MissingResourceException("Wrong header length",
                                           datafile, "");
    }

    /* Validate the magic number. */
    for (int i = 0; i < LABEL_LENGTH; i++, offset++) {
        if (buf[offset] != LABEL[offset]) {
            throw new MissingResourceException("Wrong magic number",
                                               datafile, "");
        }
    }

    /* Validate the version number. */
    if (buf[offset] != supportedVersion) {
        throw new MissingResourceException("Unsupported version(" + buf[offset] + ")",
                                           datafile, "");
    }

    /* Read data: totalDataSize + 8(for checksum) */
    len = getInt(buf, ++offset);
    buf = new byte[len];
    if (is.read(buf) != len) {
        throw new MissingResourceException("Wrong data length",
                                           datafile, "");
    }

    is.close();

    return buf;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:55,代碼來源:RuleBasedBreakIterator.java


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