Consumes remaining contents of this object, and returns them as a byte array.
()
| 91 | |
| 92 | /** Consumes remaining contents of this object, and returns them as a byte array. */ |
| 93 | public byte[] toArray() { |
| 94 | long left = bytesLeft(); |
| 95 | if (left != (int) left) { |
| 96 | throw new ArrayIndexOutOfBoundsException("Too much data to fit in one array!"); |
| 97 | } |
| 98 | byte[] ret = new byte[(int) left]; |
| 99 | for (int i = 0; i < ret.length; i++) { |
| 100 | ret[i] = nextByte(); |
| 101 | } |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | } |