1 jls.loader.provide('jls.io.FileChannel'); 2 3 jls.loader.require('jls.io.FileDescriptor'); 4 5 jls.io.FileChannel = jls.lang.Class.create(jls.io.FileDescriptor, /** @lends jls.io.FileChannel.prototype */ 6 { 7 /** 8 * Creates a file channel. 9 * 10 * @param {jls.io.File} file The file. 11 * @param {Number} [flags] The file flags. 12 * @augments jls.io.FileDescriptor 13 * @class This class represents a file channel. 14 * @constructs 15 */ 16 initialize : function($super, file, flags) { 17 var nfd = null; 18 flags = flags || jls.io.FileChannel.READ_ONLY; 19 if ((file instanceof _native.io.FileDesc) || (file instanceof _native.io.StaticFileDesc)) { 20 nfd = file; 21 } else if (file instanceof jls.io.File) { 22 nfd = new _native.io.FileDesc(file.getPath(), flags); 23 } else if (typeof file == 'string') { 24 nfd = new _native.io.FileDesc(file, flags); 25 } else { 26 throw new jls.lang.Exception('Invalid file type'); 27 } 28 if (nfd == null) { 29 throw new jls.lang.Exception('File not found'); 30 } 31 $super(nfd); 32 } 33 }); 34 35 Object.extend(jls.io.FileChannel, /** @lends jls.io.FileChannel */ 36 { 37 READ_ONLY : _native.io.FileDesc.READ_ONLY, 38 WRITE_ONLY : _native.io.FileDesc.WRITE_ONLY, 39 READ_WRITE : _native.io.FileDesc.READ_WRITE, 40 CREATE_FILE : _native.io.FileDesc.CREATE_FILE, 41 APPEND : _native.io.FileDesc.APPEND, 42 TRUNCATE : _native.io.FileDesc.TRUNCATE, 43 SYNC : _native.io.FileDesc.SYNC, 44 EXCL : _native.io.FileDesc.EXCL 45 }); 46 47