| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.drew.lang; |
| 23 |
|
| 24 |
import java.io.IOException; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public final class BufferBoundsException extends IOException |
| 32 |
{ |
| 33 |
private static final long serialVersionUID = 2911102837808946396L; |
| 34 |
|
| 35 |
public BufferBoundsException(int index, int bytesRequested, long bufferLength) |
| 36 |
{ |
| 37 |
super(getMessage(index, bytesRequested, bufferLength)); |
| 38 |
} |
| 39 |
|
| 40 |
public BufferBoundsException(final String message) |
| 41 |
{ |
| 42 |
super(message); |
| 43 |
} |
| 44 |
|
| 45 |
private static String getMessage(int index, int bytesRequested, long bufferLength) |
| 46 |
{ |
| 47 |
if (index < 0) |
| 48 |
return String.format("Attempt to read from buffer using a negative index (%d)", index); |
| 49 |
|
| 50 |
if (bytesRequested < 0) |
| 51 |
return String.format("Number of requested bytes cannot be negative (%d)", bytesRequested); |
| 52 |
|
| 53 |
if ((long)index + (long)bytesRequested - 1L > (long)Integer.MAX_VALUE) |
| 54 |
return String.format("Number of requested bytes summed with starting index exceed maximum range of signed 32 bit integers (requested index: %d, requested count: %d)", index, bytesRequested); |
| 55 |
|
| 56 |
return String.format("Attempt to read from beyond end of underlying data source (requested index: %d, requested count: %d, max index: %d)", |
| 57 |
index, bytesRequested, bufferLength - 1); |
| 58 |
} |
| 59 |
} |