Flushes the pending buffer into the given output array. If the output array is to small, only a partial flush is done. @param output the output array; @param offset the offset into output array; @param length the maximum number of bytes to store; @exception IndexOutOfBoundsException if offset or l
(byte[] output, int offset, int length)
| 159 | * invalid. |
| 160 | */ |
| 161 | public final int flush(byte[] output, int offset, int length) { |
| 162 | if (bitCount >= 8) |
| 163 | { |
| 164 | buf[end++] = (byte) bits; |
| 165 | bits >>>= 8; |
| 166 | bitCount -= 8; |
| 167 | } |
| 168 | if (length > end - start) |
| 169 | { |
| 170 | length = end - start; |
| 171 | System.arraycopy(buf, start, output, offset, length); |
| 172 | start = 0; |
| 173 | end = 0; |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | System.arraycopy(buf, start, output, offset, length); |
| 178 | start += length; |
| 179 | } |
| 180 | return length; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Flushes the pending buffer and returns that data in a new array |