本文整理汇总了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;
}
}
示例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;
}