本文整理汇总了Java中org.apache.hadoop.io.nativeio.Errno类的典型用法代码示例。如果您正苦于以下问题:Java Errno类的具体用法?Java Errno怎么用?Java Errno使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Errno类属于org.apache.hadoop.io.nativeio包,在下文中一共展示了Errno类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createForWrite
import org.apache.hadoop.io.nativeio.Errno; //导入依赖的package包/类
/**
* Open the specified File for write access, ensuring that it does not exist.
* @param f the file that we want to create
* @param permissions we want to have on the file (if security is enabled)
*
* @throws AlreadyExistsException if the file already exists
* @throws IOException if any other error occurred
*/
public static FileOutputStream createForWrite(File f, int permissions)
throws IOException {
if (skipSecurity) {
return insecureCreateForWrite(f, permissions);
} else {
// Use the native wrapper around open(2)
try {
FileDescriptor fd = NativeIO.open(f.getAbsolutePath(),
NativeIO.O_WRONLY | NativeIO.O_CREAT | NativeIO.O_EXCL,
permissions);
return new FileOutputStream(fd);
} catch (NativeIOException nioe) {
if (nioe.getErrno() == Errno.EEXIST) {
throw new AlreadyExistsException(nioe);
}
throw nioe;
}
}
}