xav
xav

Reputation: 5628

Can't a Reader read *directly* from a StringBuilder?

I'm using an API that requires a Reader to read from, and this Reader should actually read from a (potentially very large) StringBuilder.

But using this:

new StringReader(stringBuilder.toString());

...will copy the internal StringBuilder's char array, which I want to avoid due to array size. Although, this char array is package-protected.

And no better luck with StringBuffer :(

Am I missing something?

Note: I can't use Java 7 at this time.

Upvotes: 3

Views: 2378

Answers (1)

Chris Martin
Chris Martin

Reputation: 30756

StringBuilder implements CharSequence, so you can use CharSequenceReader from Apache commons-io.

Upvotes: 7

Related Questions