StringBufferInputStream deprecation

S

Silas Snider

Dear List,
I am using a DigestInputStream to perform a digest function on
passwords that get stored in an arbitrary database. (I can't use a database
function to do the same thing, because the program is designed to work with
as many dbs as possible including text files)
Anyway, I am using a StringBufferInputStream to pass a string into the
DigestInputStream, when lo and behold, Eclipse tells me that the
StringBufferInputStream class is deprecated. The api says to use
StringReader instead, but DigestInputStream accepts only InputStreams as
input. Is there another digesting class that I didn't see that will do
strings? Or is there a way to change a Reader into an InputStream?

Thanks,
Silas Snider
 
S

Sudsy

Silas said:
Dear List,
I am using a DigestInputStream to perform a digest function on
passwords that get stored in an arbitrary database. (I can't use a database
function to do the same thing, because the program is designed to work with
as many dbs as possible including text files)
Anyway, I am using a StringBufferInputStream to pass a string into the
DigestInputStream, when lo and behold, Eclipse tells me that the
StringBufferInputStream class is deprecated. The api says to use
StringReader instead, but DigestInputStream accepts only InputStreams as
input. Is there another digesting class that I didn't see that will do
strings? Or is there a way to change a Reader into an InputStream?

Always check the javadocs. Since the only constructor for
StringBufferInputStream is a java.lang.String, why not something like
this:

InputStream is = new ByteArrayInputStream( s.getBytes() );

(where s is the java.lang.String passed to the StringBufferInputStream
constructor)

You can then use is as the first argument to the DigestInputStream
constructor.
 
S

Simon Fairfax

Sudsy said:
Always check the javadocs. Since the only constructor for
StringBufferInputStream is a java.lang.String, why not something like
this:

InputStream is = new ByteArrayInputStream( s.getBytes() );

(where s is the java.lang.String passed to the StringBufferInputStream
constructor)

You can then use is as the first argument to the DigestInputStream
constructor.

Thanks! It works perfectly.
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top