Exemplo n.º 1
0
        public virtual bool copyFileTo(cape.File dest)
        {
            if (dest == null)
            {
                return(false);
            }
            if (this.isSame(dest))
            {
                return(true);
            }
            var buf = new byte[4096 * 4];

            if (buf == null)
            {
                return(false);
            }
            var reader = this.read();

            if (reader == null)
            {
                return(false);
            }
            var writer = dest.write();

            if (writer == null)
            {
                if (reader is cape.Closable)
                {
                    ((cape.Closable)reader).close();
                }
                return(false);
            }
            var v = true;
            var n = 0;

            while ((n = reader.read(buf)) > 0)
            {
                var nr = writer.write(buf, n);
                if (nr != n)
                {
                    v = false;
                    break;
                }
            }
            if (v)
            {
                var fi = this.stat();
                if (fi != null)
                {
                    var mode = fi.getMode();
                    if (mode != 0)
                    {
                        dest.setMode(mode);
                    }
                }
            }
            else
            {
                dest.remove();
            }
            if (reader != null && reader is cape.Closable)
            {
                ((cape.Closable)reader).close();
            }
            if (writer != null && writer is cape.Closable)
            {
                ((cape.Closable)writer).close();
            }
            return(v);
        }