Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (mStream != null)
     {
         mStream.Dispose();
     }
     mStream = null;
 }
Ejemplo n.º 2
0
 public SambaInputStream(SmbFile smbFile)
 {
     if (smbFile == null)
     {
         throw new ArgumentNullException("smbFile");
     }
     mFile = smbFile;
     try
     {
         mStream = new SmbFileInputStream(smbFile);
     }
     catch (SmbException ex)
     {
         throw new System.IO.IOException(ex.Message, ex);
     }
     mPos = 0;
 }
Ejemplo n.º 3
0
 /// <exception cref="System.IO.IOException"></exception>
 protected internal override void DoSendFragment(byte[] buf, int off, int length, bool isDirect)
 {
     if (Out != null && Out.IsOpen() == false)
     {
         throw new IOException("DCERPC pipe is no longer open");
     }
     if (In == null)
     {
         In = (SmbFileInputStream)Pipe.GetNamedPipeInputStream();
     }
     if (Out == null)
     {
         Out = (SmbFileOutputStream)Pipe.GetNamedPipeOutputStream();
     }
     if (isDirect)
     {
         Out.WriteDirect(buf, off, length, 1);
         return;
     }
     Out.Write(buf, off, length);
 }
 // 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);
         }
     }
                                   );
 }
Ejemplo n.º 5
0
        public override long Seek(long offset, System.IO.SeekOrigin origin)
        {
            if (mStream == null)
            {
                throw new ObjectDisposedException("SambaInputStream");
            }
            try
            {
                                #if DEBUG_SAMBA
                Android.Util.Log.Debug("SambaInputStream", "Seeking with offset " + offset + " and origin " + origin);
                                #endif
                long newPos = mPos;
                switch (origin)
                {
                case System.IO.SeekOrigin.Begin:
                    if (offset < 0)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = offset;
                    break;

                case SeekOrigin.Current:
                    if (offset < -mPos)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = mPos + offset;
                    break;

                case SeekOrigin.End:
                {
                    long len = mFile.Length();
                    if (offset > 0)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = len + offset;
                }
                break;

                default:
                    break;
                }
                if (newPos > mPos)
                {
                    mStream.Skip(newPos - mPos);
                }
                else if (newPos < mPos)
                {
                    // SmbInputStream can't seek backwards; have to recreate
                    mStream.Close();
                    mStream = new SmbFileInputStream(mFile);
                    mStream.Skip(newPos);
                }
                mPos = newPos;
                                #if DEBUG_SAMBA
                Android.Util.Log.Debug("SambaInputStream", "New position is " + mPos);
                                #endif
                return(mPos);
            }
            catch (SmbException ex)
            {
                throw new System.IO.IOException(ex.Message, ex);
            }
            catch (Java.IO.IOException ex)
            {
                throw new System.IO.IOException(ex.Message, ex);
            }
        }