MCPcopy Create free account
hub / github.com/BuildCraft/BuildCraft / ensureEmpty

Method ensureEmpty

common/buildcraft/lib/misc/MessageUtil.java:167–195  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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}

Callers 3

onMessageMethod · 0.95
handleUpdateTagMethod · 0.95
receivePayloadMethod · 0.95

Calls 2

appendMethod · 0.65
clearMethod · 0.65

Tested by

no test coverage detected