/// <summary> /// Deletes the specified file. /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public int deleteFile(String filename) throws IOException public virtual int deleteFile(string filename) { sendDeleteFileRequest(out_, Conv.stringToUnicodeByteArray(filename)); out_.flush(); int length = in_.readInt(); if (length < 24) { throw DataStreamException.badLength("deleteFile", 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); if (reqRepID == 0x8001) { int rc = in_.readShort(); int remaining = length - 24; in_.skipBytes(remaining); return(rc); } else { int remaining = length - 22; in_.skipBytes(remaining); throw DataStreamException.badReply("deleteFile", reqRepID); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public int readFile(FileHandle handle, byte[] buffer, int bufferOffset, int bufferLength) throws IOException public virtual int readFile(FileHandle handle, sbyte[] buffer, int bufferOffset, int bufferLength) { long currentOffset = handle.Offset; sendReadRequest(handle.Handle, currentOffset, bufferLength); out_.flush(); int length = in_.readInt(); if (length < 24) { throw DataStreamException.badLength("readFile", 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 remaining = length - 22; int rc = 0; int numToRead = -1; if (reqRepID == 0x8001) { rc = in_.readShort(); remaining -= 2; numRead += 2; } else if (reqRepID == 0x8003) { int ccsid = in_.readShort(); int dataLength = in_.readInt(); in_.skipBytes(2); remaining -= 8; int numBytes = dataLength - 6; numToRead = numBytes > length ? length : numBytes; int numToSkip = numToRead >= numBytes ? 0 : numBytes - length; in_.readFully(buffer, bufferOffset, numToRead); in_.skipBytes(numToSkip); handle.Offset = currentOffset + numToRead; remaining -= numBytes; numRead += 6; numRead += numToRead; numRead += numToSkip; } else { in_.skipBytes(remaining); numRead += remaining; throw DataStreamException.badReply("readFile", reqRepID); } in_.skipBytes(remaining - 2); handle.LastStatus = rc; return(numToRead); }
/// <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; }
//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); } }
//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); }
/// <summary> /// Returns a list of filenames 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> /// To return more than just the names of files, use <seealso cref="#listFiles listFiles()"/>. /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public java.util.List<String> list(String dir) throws IOException public virtual IList <string> list(string dir) { // System.out.println("Server CCSID: "+getInfo().getServerCCSID()); if (dir.IndexOf("*", StringComparison.Ordinal) < 0) { if (!dir.EndsWith("/", StringComparison.Ordinal)) { dir = dir + "/*"; } else { dir = dir + "*"; } } sendListFilesRequest(Conv.stringToUnicodeByteArray(dir)); out_.flush(); List <string> files = new List <string>(); 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 = in_.readLong(); * long modifyDate = in_.readLong(); * long actual = ((modifyDate >> 32) & 0x00FFFFFFFFL)*1000L + ((modifyDate & 0x00FFFFFFFFL)/1000); * System.out.println(new java.util.Date(actual)); * long accessDate = in_.readLong(); * 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 */ in_.skipBytes(70); 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("..")) { files.Add(name); } int remaining = length - numRead; in_.skipBytes(remaining); } else { int remaining = length - 22; in_.skipBytes(remaining); throw DataStreamException.badReply("listFiles", reqRepID); } } return(files); }
/// <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); }