Beispiel #1
0
        public virtual bool write(cape.File outfile)
        {
            if (!(outfile != null))
            {
                return(false);
            }
            if (!(data != null))
            {
                return(false);
            }
            var os = cape.PrintWriterWrapper.forWriter((cape.Writer)outfile.write());

            if (!(os != null))
            {
                return(false);
            }
            var it = data.iterate();

            while (it != null)
            {
                var kvp = it.next();
                if (!(kvp != null))
                {
                    break;
                }
                os.println(kvp.key + ": " + kvp.value);
            }
            return(true);
        }
Beispiel #2
0
        public virtual bool writeToFile(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            if (getIsDirectory())
            {
                return(file.createDirectoryRecursive());
            }
            var reader = getContentReader();

            if (!(reader != null))
            {
                return(false);
            }
            var fp = file.getParent();

            if (fp != null)
            {
                fp.createDirectoryRecursive();
            }
            var writer = file.write();

            if (!(writer != null))
            {
                if (reader is cape.Closable)
                {
                    ((cape.Closable)reader).close();
                }
                return(false);
            }
            var buf = new byte[4096 * 4];
            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)
            {
                file.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);
        }
Beispiel #3
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);
        }