Java stream file to socket as fast as possible -
i have file of bytes mybytes.dat
, , i'm writing tcp server/client, server sends contents of mybytes.dat
client on socket.
if mybytes.dat
read memory, application can send data @ 160mb/s on local network stack. however, i'm trying stream datafiles > 1gb, , shouldn't read memory.
this related solution sending file in chunks seems appropriate; however, more efficient read large chunks of file memory (ie. maybe 1mb @ time in buffer) , write these smaller chunks (32kb) socket? if reasonable, how can 1 use bufferedfilereader read large chunks, , write smaller chunks outputstream? started, let me declare @ least variables:
bufferedinputstream blobreader = new bufferedinputstream(newinputstream("mybytes.dat"), 1024*1024); outputstream socketwriter = socket.getoutputstream();
what correct way connect blobreader socketwriter, such maintain enough bytes in memory ensure application not limited disk reads? or offbase line of reasoning?
Comments
Post a Comment