Esempio n. 1
0
 public override int Read(byte[] buffer, int offset, int count)
 {
     if (mStream == null)
     {
         throw new ObjectDisposedException("SambaInputStream");
     }
     try
     {
         int res = SmbOperations.WithRetries(() =>
         {
             return(mStream.Read(buffer, offset, count));
         });
         // note: java.io.Stream.Read returns -1 on end of input, but
         // System.IO.Stream must return 0 in that case
         if (res == -1)
         {
                                 #if DEBUG_SAMBA
             Android.Util.Log.Debug("SambaInputStream", "End of stream reached at " + mPos + "(length is " + mFile.Length() + ")");
                                 #endif
             res = 0;
         }
         else
         {
             mPos += res;
                                 #if DEBUG_SAMBA
             Android.Util.Log.Debug("SambaInputStream", "Read " + res + " bytes from stream, new pos is " + mPos);
                                 #endif
         }
         return(res);
     }
     catch (SmbException ex)
     {
         throw new System.IO.IOException(ex.Message, ex);
     }
     catch (Java.IO.IOException ex)
     {
         throw new System.IO.IOException(ex.Message, ex);
     }
 }
Esempio n. 2
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal override void DoReceiveFragment(byte[] buf, bool isDirect)
        {
            int off;
            int flags;
            int length;

            if (buf.Length < MaxRecv)
            {
                throw new ArgumentException("buffer too small");
            }
            if (IsStart && !isDirect)
            {
                // start of new frag, do trans
                off = In.Read(buf, 0, 1024);
            }
            else
            {
                off = In.ReadDirect(buf, 0, buf.Length);
            }
            if (buf[0] != 5 && buf[1] != 0)
            {
                throw new IOException("Unexpected DCERPC PDU header");
            }
            flags = buf[3] & unchecked (0xFF);
            // next read is start of new frag
            IsStart = (flags & DcerpcConstants.DcerpcLastFrag) == DcerpcConstants.DcerpcLastFrag;
            length  = Encdec.Dec_uint16le(buf, 8);
            if (length > MaxRecv)
            {
                throw new IOException("Unexpected fragment length: " + length);
            }
            while (off < length)
            {
                off += In.ReadDirect(buf, off, length - off);
            }
        }
 // This is NOT best-practice code, just showing a demo Jcifs api call
 public async Task getFileContents()
 {
     await Task.Run(() => {
         var smbStream = new SmbFileInputStream("smb://*****:*****@file_server//d.txt");
         byte[] b      = new byte[8192];
         int n;
         while ((n = smbStream.Read(b)) > 0)
         {
             Console.Write(Encoding.UTF8.GetString(b).ToCharArray(), 0, n);
         }
         Button button = FindViewById <Button> (Resource.Id.myButton);
         RunOnUiThread(() => {
             button.Text = Encoding.UTF8.GetString(b);
         });
     }
                    ).ContinueWith((Task arg) => {
         Console.WriteLine(arg.Status);
         if (arg.Status == TaskStatus.Faulted)
         {
             Console.WriteLine(arg.Exception);
         }
     }
                                   );
 }