NetHadoop.FSClient.Open C# (CSharp) Method

Open() public method

public Open ( ThriftHadoopFileSystem client, string path, string savePath, long fileLength ) : bool
client ThriftHadoopFileSystem
path string
savePath string
fileLength long
return bool
        public bool Open(ThriftHadoopFileSystem.Client client,string path,string savePath,long fileLength)
        {
            bool result = false;
               if (client != null)
               {
               ThriftHandle th = client.open(new Pathname() { pathname = path });

               // 创建文件流
               FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.Write);
               long totalBytes = 0;
               int readLength=1024*1024;
               try
               {
                   UTF8Encoding utf8 = new UTF8Encoding(false,true);

                   while (true)
                   {
                       int needRead = readLength;
                       if (fileLength - totalBytes < readLength)
                       {
                           needRead = (int)(fileLength - totalBytes);
                       }
                       if (needRead <= 0)
                           break;

                       byte[] fileBuffer = client.read(th, totalBytes, readLength);

                       byte[] myfileBuffer =  Encoding.Convert(utf8, Encoding.GetEncoding("iso-8859-1"), fileBuffer);

                       totalBytes += readLength;

                       fs.Write(myfileBuffer, 0, myfileBuffer.Length);

                   }
                   result = true;

               }
               catch (Exception ee)
               {
                   throw ee;
               }
               finally
               {
                   fs.Dispose();
                   if (client != null)
                       client.close(th);
               }
               }
               return result;
        }