Example #1
0
    private void ReadFile()
    {
        // Ask for a file
        Gnome.Vfs.Uri uri = FileDialog.OpenFile("Read File");

        // Create Stream
        Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream(uri.ToString(), FileMode.Open);

        // Read File byte by byte
        while (true)
        {
            int c = vs.ReadByte();

            if (c < 0)
            {
                Console.WriteLine("EOF");
                break;
            }

            Console.Write((char)c);
        }

        // Close File
        vs.Close();
    }
		static void Main (string[] args)
		{
			if (args.Length != 1) {
				Console.WriteLine ("Usage: TestAsyncStream <uri>");
				return;
			}
		
			Gnome.Vfs.Vfs.Initialize ();

			VfsStream stream = new VfsStream (args[0], FileMode.Open, true);
			
			UTF8Encoding utf8 = new UTF8Encoding ();
			buffer = new byte[1024];
			int read;
			while ((read = stream.Read (buffer, 0, buffer.Length)) != 0) {
				Console.WriteLine ("read ({0} bytes) : '{1}'",
						   read, utf8.GetString (buffer, 0, read));
			}

			long offset = stream.Seek (0, SeekOrigin.Begin);
			Console.WriteLine ("Offset after seek is {0}", offset);
			
			buffer = new byte[1024];
			IAsyncResult result = stream.BeginRead (buffer, 0, buffer.Length,
								new System.AsyncCallback (OnReadComplete),
								stream);

			loop = new MainLoop ();
			loop.Run ();

			Gnome.Vfs.Vfs.Shutdown ();
		}
Example #3
0
    private void WriteFile()
    {
        // Ask for a file
        Gnome.Vfs.Uri uri = FileDialog.SaveFile("Write to File");

        // Create Stream
        Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream(uri.ToString(), FileMode.CreateNew);

        // Write to the file
        UTF8Encoding utf8 = new UTF8Encoding();

        byte [] buf = utf8.GetBytes("Testing 1 2 3, asdjfaskjdhfkajshdf");
        vs.Write(buf, 0, buf.Length);

        // Close the file
        vs.Close();
    }
		static void Main (string[] args)
		{
			if (args.Length != 1) {
				Console.WriteLine ("Usage: TestSyncStream <uri>");
				return;
			}
		
			Gnome.Vfs.Vfs.Initialize ();

			VfsStream stream = new VfsStream (args[0], FileMode.Open);
			
			UTF8Encoding utf8 = new UTF8Encoding ();
			byte[] buffer = new byte[1024];
			int read;
			while ((read = stream.Read (buffer, 0, buffer.Length)) != 0) {
				Console.WriteLine ("read ({0} bytes) : '{1}'",
						   read, utf8.GetString (buffer, 0, read));
			}

			long offset = stream.Seek (0, SeekOrigin.Begin);
			Console.WriteLine ("Offset after seek is {0}", offset);
			
			Gnome.Vfs.Vfs.Shutdown ();
		}
 private void ReadFile()
 {
         // Ask for a file
         Gnome.Vfs.Uri uri = FileDialog.OpenFile ("Read File");
 
         // Create Stream
         Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream (uri.ToString (), FileMode.Open);
 
         // Read File byte by byte
         while (true) {
                 int c = vs.ReadByte ();
 
                 if (c < 0) {
                         Console.WriteLine ("EOF");
                         break;
                 }
 
                 Console.Write ((char) c);
         }
 
         // Close File
         vs.Close ();
 }
 private void WriteFile ()
 {
         // Ask for a file
         Gnome.Vfs.Uri uri = FileDialog.SaveFile ("Write to File");
 
         // Create Stream
         Gnome.Vfs.VfsStream vs = new Gnome.Vfs.VfsStream (uri.ToString (), FileMode.CreateNew);
 
         // Write to the file
         UTF8Encoding utf8 = new UTF8Encoding ();
         byte [] buf = utf8.GetBytes ("Testing 1 2 3, asdjfaskjdhfkajshdf");
         vs.Write (buf, 0, buf.Length);
 
         // Close the file
         vs.Close();
 }