Java Code Examples for java.security.PrivilegedActionException.toString()

The following are Jave code examples for showing how to use toString() of the java.security.PrivilegedActionException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: NbfsUtil.java   View Source Code Vote up 5 votes
/**
 * 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;
    }
}
 
Example 2
Project: OpenJSharp   File: RuleBasedBreakIterator.java   View Source Code Vote up 4 votes
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;
}
 
Example 3
Project: jdk8u-jdk   File: RuleBasedBreakIterator.java   View Source Code Vote up 4 votes
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;
}