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();
}
if (flags.isCreate()) {
if (theFile.exists() && flags.isExclusive()) {
throw new FileExistsException(path);
}
fileCreated = theFile.createNewFile();
} else {
if (!theFile.exists()) {
throw new FileNotFoundException(path);
}
}
// We always open this rw since we can only open it r or rw.
RandomAccessFile file = new RandomAccessFile(theFile, flags.toJavaModeString());
// call chmod after we created the RandomAccesFile
// because otherwise, the file could be read-only
if (fileCreated) {
// attempt to set the permissions, if we have been passed a POSIX instance,
// and only if the file was created in this call.
if (posix != null && perm != -1) {
posix.chmod(theFile.getPath(), perm);
}
}
if (flags.isTruncate()) file.setLength(0L);