Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Http Reader.read(CharBuffer) for Binary?  RSS feed

 
Saverio Miroddi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a short way to use NIO client-side for binary files in a HTTP connection?

for chars there is:

URLConnetion conn = url.openConnection();
CharBuffer cbuf = CharBuffer.allocate(conn.getContentLength());
Reader reader = new InputStreamReader(conn.getInputStream());
while (reader.read(cbuf) != 0) { }

is there a simple way, similar to this to download a binary file from an URL (HTTP) connection?

Thanks!
Saverio M.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try replacing CharBuffer with ByteBuffer?
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Reader for binary files, use directly the InputStream (and ByteBuffer instead of CharBuffer).
 
Saverio Miroddi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>so if i want to read binary data from a Socket via NIO
>i have to write much code.

i meant: from a HttpConnection, to be exact.

Bye!
[ December 13, 2006: Message edited by: Saverio J(ava) Miroddi ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!