public static ChannelDescriptor open(String cwd, String path, ModeFlags flags, int perm, POSIX posix) throws FileNotFoundException, DirectoryAsFileException, FileExistsException, IOException {
boolean fileCreated = false;
if (path.equals("/dev/null") || path.equalsIgnoreCase("nul:") || path.equalsIgnoreCase("nul")) {
Channel nullChannel = new NullChannel();
// FIXME: don't use RubyIO for this
return new ChannelDescriptor(nullChannel, RubyIO.getNewFileno(), flags, new FileDescriptor());
} else if(path.startsWith("file:")) {
String filePath = path.substring(5, path.indexOf("!"));
String internalPath = path.substring(path.indexOf("!") + 2);
if (!new File(filePath).exists()) {
throw new FileNotFoundException(path);
}
JarFile jf = new JarFile(filePath);
ZipEntry zf = jf.getEntry(internalPath);
if(zf == null) {
throw new FileNotFoundException(path);
}
InputStream is = jf.getInputStream(zf);
// FIXME: don't use RubyIO for this
return new ChannelDescriptor(Channels.newChannel(is), RubyIO.getNewFileno(), flags, new FileDescriptor());
} else {
JRubyFile theFile = JRubyFile.create(cwd,path);
if (theFile.isDirectory() && flags.isWritable()) {
throw new DirectoryAsFileException();