…lines 1–141 unchanged (141 lines)
142 throw new IndexOutOfBoundsException();
143 } else if (offset > b.length || offset + len > b.length) {
144 throw new IndexOutOfBoundsException();
145 } else if (len == 0) {
146 return 0;
147 } else {
148 /*
149 Rationale for while-loop on (readLen == 0):
150 -----
151 Base64.readResults() usually returns > 0 or EOF (-1). In the
152 rare case where it returns 0, we just keep trying.
153
154 This is essentially an undocumented contract for InputStream
155 implementors that want their code to work properly with
156 java.io.InputStreamReader, since the latter hates it when
157 InputStream.read(byte[]) returns a zero. Unfortunately our
158 readResults() call must return 0 if a large amount of the data
159 being decoded was non-base64, so this while-loop enables proper
160 interop with InputStreamReader for that scenario.
161 -----
162 This is a fix for CODEC-101
163 */
164 if (!base64.hasData()) {
165 byte[] buf = new byte[doEncode ? 4096 : 8192];
166 int c = in.read(buf);
167 // A little optimization to avoid System.arraycopy()
168 // when possible.
169 if (c > 0 && b.length == len) {
170 base64.setInitialBuffer(b, offset, len);
171 }
172 if (doEncode) {
173 base64.encode(buf, 0, c);
174 } else {
175 base64.decode(buf, 0, c);
176 }
177 }
178 return base64.readResults(b, offset, len);
179 }
180 }
181
182 /**
183 * {@inheritDoc}
184 *
…lines 185–191 unchanged (7 lines)