| 330 | } |
| 331 | |
| 332 | private static final class ByteArrayBody implements Response.Body { |
| 333 | |
| 334 | private final byte[] data; |
| 335 | |
| 336 | public ByteArrayBody(byte[] data) { |
| 337 | this.data = data; |
| 338 | } |
| 339 | |
| 340 | private static Body orNull(byte[] data) { |
| 341 | if (data == null) { |
| 342 | return null; |
| 343 | } |
| 344 | return new ByteArrayBody(data); |
| 345 | } |
| 346 | |
| 347 | private static Body orNull(String text, Charset charset) { |
| 348 | if (text == null) { |
| 349 | return null; |
| 350 | } |
| 351 | checkNotNull(charset, "charset"); |
| 352 | return new ByteArrayBody(text.getBytes(charset)); |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public Integer length() { |
| 357 | return data.length; |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public boolean isRepeatable() { |
| 362 | return true; |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public InputStream asInputStream() { |
| 367 | return new ByteArrayInputStream(data); |
| 368 | } |
| 369 | |
| 370 | @SuppressWarnings("deprecation") |
| 371 | @Override |
| 372 | public Reader asReader() { |
| 373 | return new InputStreamReader(asInputStream(), UTF_8); |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public Reader asReader(Charset charset) { |
| 378 | checkNotNull(charset, "charset should not be null"); |
| 379 | return new InputStreamReader(asInputStream(), charset); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void close() {} |
| 384 | } |
| 385 | } |
nothing calls this directly
no outgoing calls
no test coverage detected