Checks to make sure that this buffer has been completely read (so that there are no readable bytes left over
(ByteBuf buf, boolean throwError, String extra)
| 165 | /** Checks to make sure that this buffer has been *completely* read (so that there are no readable bytes left |
| 166 | * over */ |
| 167 | public static void ensureEmpty(ByteBuf buf, boolean throwError, String extra) { |
| 168 | int readableBytes = buf.readableBytes(); |
| 169 | if (readableBytes > 0) { |
| 170 | // Get a (small) bit of the data |
| 171 | byte[] selection = new byte[readableBytes > 10 ? 10 : readableBytes]; |
| 172 | buf.readBytes(selection); |
| 173 | StringBuilder sb = new StringBuilder(); |
| 174 | for (byte b : selection) { |
| 175 | String h = Integer.toHexString(Byte.toUnsignedInt(b)); |
| 176 | if (h.length() == 1) { |
| 177 | sb.append(" 0"); |
| 178 | } else { |
| 179 | sb.append(" "); |
| 180 | } |
| 181 | sb.append(h); |
| 182 | } |
| 183 | if (readableBytes > 10) { |
| 184 | sb.append(" (+" + (readableBytes - 10) + ")"); |
| 185 | } |
| 186 | |
| 187 | IllegalStateException ex = new IllegalStateException("Did not fully read the data! [" + extra + "]" + sb); |
| 188 | if (throwError) { |
| 189 | throw ex; |
| 190 | } else { |
| 191 | BCLog.logger.warn(ex); |
| 192 | } |
| 193 | buf.clear(); |
| 194 | } |
| 195 | } |
| 196 | } |
no test coverage detected