2222import java .net .http .HttpResponse .BodySubscriber ;
2323import java .nio .ByteBuffer ;
2424import java .util .ArrayList ;
25- import java .util .Collection ;
2625import java .util .Collections ;
2726import java .util .List ;
2827import java .util .concurrent .CompletionStage ;
@@ -103,20 +102,14 @@ public void onNext(List<ByteBuffer> item) {
103102
104103 private List <ByteBuffer > decompress (InputStream decStream ) throws IOException {
105104 List <ByteBuffer > dec = new ArrayList <>(1 );
106- ByteBuffer buf = newBuffer ();
107105
108106 try (var stream = decStream ) {
107+ byte [] buf = new byte [bufferSize ];
109108 int r ;
110- while ((r = stream .read ()) != -1 ) {
111- if (!buf .hasRemaining ()) {
112- add (dec , buf );
113- buf = newBuffer ();
114- }
115-
116- buf .put ((byte ) r );
109+ while ((r = stream .read (buf )) > 0 ) {
110+ ByteBuffer bb = ByteBuffer .allocate (r ).put (buf , 0 , r ).flip ();
111+ dec .add (bb );
117112 }
118-
119- add (dec , buf );
120113 }
121114
122115 return Collections .unmodifiableList (dec );
@@ -140,16 +133,6 @@ private void pushNext(List<ByteBuffer> item) {
140133 }
141134 }
142135
143- private ByteBuffer newBuffer () {
144- return ByteBuffer .allocate (bufferSize );
145- }
146-
147- private void add (Collection <ByteBuffer > decompressed , ByteBuffer buf ) {
148- if (buf .position () > 0 ) {
149- decompressed .add (buf .flip ());
150- }
151- }
152-
153136 private InputStream initDecompressingStream () {
154137 try {
155138 is .mark (32 );
0 commit comments