Esempio n. 1
0
        /// <summary>
        /// Writes data to the file starting at the current file offset in the handle, and optionally sync-ing the data to disk;
        /// upon a successful write, the current file offset and size are incremented.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeFile(FileHandle handle, byte[] buffer, int bufferOffset, int bufferLength, boolean sync) throws IOException
        public virtual void writeFile(FileHandle handle, sbyte[] buffer, int bufferOffset, int bufferLength, bool sync)
        {
            long currentOffset = handle.Offset;

            sendWriteRequest(handle.Handle, currentOffset, buffer, bufferOffset, bufferLength, handle.DataCCSID, sync);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("writeFile", length);
            }
            int headerID       = in_.readShort();
            int serverID       = in_.readShort();
            int csInstance     = in_.readInt();
            int correlationID  = in_.readInt();
            int templateLength = in_.readShort();
            int reqRepID       = in_.readShort();
            int chain          = in_.readShort(); //in_.skipBytes(2);
            int numRead        = 22;
            int rc             = 0;

            if (reqRepID == 0x8001)
            {
                rc       = in_.readShort();
                numRead += 2;
            }
            else if (reqRepID == 0x800B)
            {
                rc = in_.readShort();
                int previousFileSize = in_.readInt();
                int bytesNotWritten  = in_.readInt();
                numRead      += 10;
                handle.Offset = currentOffset + (bufferLength - bytesNotWritten);
                handle.Size   = handle.Size + (bufferLength - bytesNotWritten);
            }
            else
            {
                in_.skipBytes(length - numRead);
                numRead = length;
                throw DataStreamException.badReply("writeFile", reqRepID);
            }
            in_.skipBytes(length - numRead);
            handle.LastStatus = rc;
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int closeFile(FileHandle handle) throws IOException
        public virtual int closeFile(FileHandle handle)
        {
            if (!handle.Open)
            {
                // Someone is trying to close an already-closed handle!
                //TODO
                return(-1);
            }
            sendCloseFileRequest(handle.Handle);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("closeFile", length);
            }
            int headerID       = in_.readShort();
            int serverID       = in_.readShort();
            int csInstance     = in_.readInt();
            int correlationID  = in_.readInt();
            int templateLength = in_.readShort();
            int reqRepID       = in_.readShort();

            in_.skipBytes(2);
            int remaining = length - 22;

            if (reqRepID == 0x8001 || reqRepID == 0x8004)
            {
                int rc = in_.readShort();
                in_.skipBytes(remaining - 2);
                return(rc);
            }
            else
            {
                in_.skipBytes(remaining);
                throw DataStreamException.badReply("closeFile", reqRepID);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Opens a file for read-write access, a share option of SHARE_ALL, and a data CCSID of 1208 (UTF-8).
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int openFile(String filename, FileHandle buffer) throws IOException
        public virtual int openFile(string filename, FileHandle buffer)
        {
            return(openFile(filename, buffer, FileHandle.OPEN_READ_WRITE, FileHandle.SHARE_ALL, true, 1208));
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int openFile(String filename, FileHandle buffer, int openType, int shareOption, boolean createIfNotExist, int dataCCSID) throws IOException
        public virtual int openFile(string filename, FileHandle buffer, int openType, int shareOption, bool createIfNotExist, int dataCCSID)
        {
            if (buffer.Open)
            {
                // Someone is re-using their buffer without closing the file!
                //TODO closeFile(buffer);
            }
            sendOpenFileRequest(Conv.stringToUnicodeByteArray(filename), openType, shareOption, createIfNotExist, dataCCSID);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("openFile", length);
            }
            int headerID       = in_.readShort();
            int serverID       = in_.readShort();
            int csInstance     = in_.readInt();
            int correlationID  = in_.readInt();
            int templateLength = in_.readShort();
            int reqRepID       = in_.readShort();

            in_.skipBytes(2);
            int remaining = length - 22;
            int rc        = 0;

            if (reqRepID == 0x8001)
            {
                rc         = in_.readShort();
                remaining -= 2;
            }
            else if (reqRepID == 0x8002)
            {
                int  handle = in_.readInt();
                long id     = in_.readLong();
                dataCCSID = in_.readShort();
                int  actionTaken           = in_.readShort();
                long createDate            = convertDate(in_);
                long modifyDate            = convertDate(in_);
                long accessDate            = convertDate(in_);
                int  fileSize              = in_.readInt();
                long actualFileSize        = fileSize;
                int  fixedAttribs          = in_.readInt();
                int  needExtAttribs        = in_.readShort();
                int  numExtAttribs         = in_.readShort();
                int  charsExtAttribsNames  = in_.readInt();
                int  bytesExtAttribsValues = in_.readInt();
                int  version        = in_.readInt();
                int  amountAccessed = in_.readShort();
                int  accessHistory  = in_.readByte();
                remaining -= 67;
                if (length >= 97)
                {
                    long largeFileSize = in_.readLong();
                    remaining     -= 8;
                    actualFileSize = largeFileSize;
                }
                buffer.Open       = true;
                buffer.OpenType   = openType;
                buffer.Name       = filename;
                buffer.Handle     = handle;
                buffer.ID         = id;
                buffer.DataCCSID  = dataCCSID;
                buffer.CreateDate = createDate;
                buffer.ModifyDate = modifyDate;
                buffer.AccessDate = accessDate;
                buffer.Size       = actualFileSize;
                buffer.Version    = version;
            }
            else
            {
                in_.skipBytes(remaining);
                throw DataStreamException.badReply("openFile", reqRepID);
            }
            in_.skipBytes(remaining - 2);
            return(rc);
        }
Esempio n. 5
0
        /// <summary>
        /// Returns a list of files under the specified directory or file spec.
        /// For example, these all return the same file listing:
        /// <ul>
        /// <li>list("/home/smith")</li>
        /// <li>list("/home/smith/*")</li>
        /// <li>list("/home/smith/../smith")</li>
        /// </ul>
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public java.util.List<FileHandle> listFiles(String dir) throws IOException
        public virtual IList <FileHandle> listFiles(string dir)
        {
            if (dir.IndexOf("*", StringComparison.Ordinal) < 0)
            {
                if (!dir.EndsWith("/", StringComparison.Ordinal))
                {
                    dir = dir + "/*";
                }
                else
                {
                    dir = dir + "*";
                }
            }

            string parent = dir;
            int    slash  = parent.LastIndexOf("/", StringComparison.Ordinal);

            if (slash < 0)
            {
                parent = "";
            }
            else if (slash > 0)
            {
                parent = parent.Substring(0, slash + 1);
            }

            sendListFilesRequest(Conv.stringToUnicodeByteArray(dir));
            out_.flush();

            List <FileHandle> files = new List <FileHandle>();
            int chain = 1;

            while (chain != 0)
            {
                int length = in_.readInt();
                if (length < 24)
                {
                    throw DataStreamException.badLength("listFiles", length);
                }
                int headerID       = in_.readShort();
                int serverID       = in_.readShort();
                int csInstance     = in_.readInt();
                int correlationID  = in_.readInt();
                int templateLength = in_.readShort();
                int reqRepID       = in_.readShort();
                chain = in_.readShort();
                if (reqRepID == 0x8001)
                {
                    int rc        = in_.readShort();
                    int remaining = length - 24;
                    in_.skipBytes(remaining);
                    if (rc != FileConstants.RC_NO_MORE_FILES)
                    {
                        throw DataStreamException.badReturnCode("listFiles", rc);
                    }
                }
                else if (reqRepID == 0x8005)
                {
                    int  numRead         = 22;
                    long createDate      = convertDate(in_);
                    long modifyDate      = convertDate(in_);
                    long accessDate      = convertDate(in_);
                    int  fileSize        = in_.readInt();
                    int  fixedAttributes = in_.readInt();
                    int  objectType      = in_.readShort();
                    int  numExtAttrs     = in_.readShort();
                    int  bytesEANames    = in_.readInt();
                    int  bytesEAValues   = in_.readInt();
                    int  version         = in_.readInt();
                    int  amountAccessed  = in_.readShort();
                    int  accessHistory   = in_.readByte();
                    int  fileCCSID       = in_.readShort();
                    int  checkoutCCSID   = in_.readShort();
                    int  restartID       = in_.readInt();
                    long largeFileSize   = in_.readLong();
                    in_.skipBytes(2);
                    int symlink = in_.readByte();     // 91
                    numRead = 92;
                    int fileNameLLOffset = 20 + templateLength;
                    int toSkip           = fileNameLLOffset - numRead;
                    in_.skipBytes(toSkip);
                    numRead += toSkip;
                    int fileNameLength = in_.readInt() - 6;
                    in_.skipBytes(2);     // 0x0002 -- Name CP.
                    numRead += 6;
                    sbyte[] nameBuf = new sbyte[fileNameLength];
                    in_.readFully(nameBuf);
                    numRead += fileNameLength;
                    string name = Conv.unicodeByteArrayToString(nameBuf, 0, nameBuf.Length);
                    if (!name.Equals(".") && !name.Equals(".."))
                    {
                        FileHandle h = FileHandle.createEmptyHandle();
                        h.Name       = name;
                        h.Path       = parent + name;
                        h.DataCCSID  = fileCCSID;
                        h.CreateDate = createDate;
                        h.ModifyDate = modifyDate;
                        h.AccessDate = accessDate;
                        h.Size       = largeFileSize;
                        h.Version    = version;
                        h.Symlink    = symlink == 1;
                        h.Directory  = objectType == 2;
                        files.Add(h);
                    }
                    int remaining = length - numRead;
                    in_.skipBytes(remaining);
                }
                else
                {
                    int remaining = length - 22;
                    in_.skipBytes(remaining);
                    throw DataStreamException.badReply("listFiles", reqRepID);
                }
            }
            return(files);
        }