get ByteBuffer from InputStream

J

Jimmy Zhang

Hi,

I am looking for ways to get access to InputStream's underlying byte
buffer structure. I heard that I have to
look into the java.nio class for that. So far haven't found it. Any help is
greatly appreciated.

Cheers,
Jimmy
 
A

Andrew Hobbs

Jimmy Zhang said:
Hi,

I am looking for ways to get access to InputStream's underlying byte
buffer structure. I heard that I have to
look into the java.nio class for that. So far haven't found it. Any help is
greatly appreciated.

What type of input stream? Input Stream is an abstract Class and it doesn't
have an underlying byte buffer. It just defines a few methods for reading
bytes into byte arrays. BufferedInputStream has a buffer which in fact you
can access if you extend the class since the buffer has protected access.

However, why do you want to access the buffer?

Unless you are very careful, if you do anything with the buffer you have a
good chance of stuffing up the working of the class. And if you think that
you might speed up the reading of the data (which you probably won't) then
simply do a read providing a large byte array (larger than the default size
of 2048). In that case the data is read directly into that buffer instead of
the internal buffer anyway.

In any case why not just examine the code in the java classes. It is
provided in the SDK.

Cheers

Andrew

--
********************************************************
Andrew Hobbs PhD

MetaSense Pty Ltd - www.metasense.com.au
12 Ashover Grove
Carine W.A.
Australia 6020

61 8 9246 2026
metasens AntiSpam @iinet dot net dot au


*********************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top