471,330 Members | 1,178 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

byte Array To File Stream

Hello,

I have a byte array and i must send(to blocks) to remote class
In the remote class i write a file stream......

How?
In my sample i send stream...

Code CLIENT:

FSource = New FileStream("c:\test.tif", FileMode.Open)
While FSource.Position < FSource.Length - 1
Call RemoteObject.WriteStream(FSource)
End While

Code SERVER:

Public Sub WriteStream(ByVal SourceStream As Stream)
Dim FOutput As FileStream

If Not File.Exists("c:\testremote.tif") Then
FOutput = New FileStream("c:\testremote.tif", FileMode.CreateNew,
FileAccess.ReadWrite)
Else
FOutput = New FileStream("c:\testremote.tif", FileMode.Append,
FileAccess.Write)
End If

Dim BWriter As BinaryWriter = New BinaryWriter(FOutput)
Dim i As Integer
Dim intBytesRead As Integer
Const intSize As Integer = 4096
Dim bytes(intSize) As Byte
intBytesRead = SourceStream.Read(bytes, 0, intSize)
BWriter.Write(bytes, 0, intBytesRead)
BWriter.Close()
FOutput.Close()
End Sub
Jul 22 '05 #1
1 9330


Gigi wrote:
Hello,

I have a byte array and i must send(to blocks) to remote class
In the remote class i write a file stream......

How?


Are you just trying to write to a remote strem? Why dont you simply use
the "Read" and "Write" methods on the Stream with the data you wish to
write. whether it is remote or not should not matter.

remote.Write(bytes, 0, bytes.Length);

If you are trying to pass a stream to a remote class, you can "just do it":

public class RemoteThingy {
void f(Stream s) {
using ( TextWriter w = new StreamWriter(s) )
w.WriteLine("Hello Remote!");
s.Flush();
}
}

public class Client {
RemoteThingy remote = ...; // obtain remote instance
using ( Stream s = new FileStream("mytest.txt")
remote.f(s);
}

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sathyaish | last post: by
1 post views Thread by steve | last post: by
1 post views Thread by Angel Filev | last post: by
8 posts views Thread by frekster | last post: by
3 posts views Thread by Terry | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.