private int writeString(final DataOutput output, String string, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (string == null) { output.write(ST_NULL); return cnt; } // make sure we never duplicate a string string = stringCache.computeIfAbsent(string, Function.identity()); final int idx = seen.get(string, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { seen.put(string, cnt); output.write(ST_NEW_STRING); output.writeUTF(string); return cnt + 1; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeStackElement(final DataOutput output, final StackTraceElement element, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, int cnt) throws IOException { final int idx = seen.get(element, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { output.write(ST_NEW_STACK_ELEMENT_V8); cnt = writeString(output, element.getClassName(), seen, stringCache, cnt); cnt = writeString(output, element.getMethodName(), seen, stringCache, cnt); cnt = writeString(output, element.getFileName(), seen, stringCache, cnt); writePackedInt(output, element.getLineNumber()); seen.put(element, cnt++); return cnt; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeThrowable(final DataOutput output, final Throwable throwable, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (throwable == null) { output.write(ST_NULL); return cnt; } else { final int idx = seen.get(throwable, - 1); final int distance = cnt - idx; if (idx == - 1 || distance >= 0x4000) { RemoteExceptionCause nested; if (throwable instanceof RemoteExceptionCause) { nested = (RemoteExceptionCause) throwable; } else { seen.put(throwable, cnt); // do not increment yet nested = of(throwable); } return nested.writeToStream(output, seen, stringCache, cnt); // this will increment it } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } } }
private int writeToStream(DataOutput output, IdentityIntMap<Object> seen, HashMap<String, String> stringCache, int cnt) throws IOException { // register in cycle map seen.put(this, cnt++); // write the header byte output.writeByte(ST_NEW_EXCEPTION_CAUSE); // first write class name cnt = writeString(output, exceptionClassName, seen, stringCache, cnt); // null or message cnt = writeString(output, getMessage(), seen, stringCache, cnt); // stack trace cnt = writeStackTrace(output, getStackTrace(), seen, stringCache, cnt); // fields cnt = writeFields(output, fields, seen, stringCache, cnt); // caused-by cnt = writeThrowable(output, getCause(), seen, stringCache, cnt); // suppressed final Throwable[] suppressed = getSuppressed(); writePackedInt(output, suppressed.length); for (final Throwable t : suppressed) { cnt = writeThrowable(output, t, seen, stringCache, cnt); } return cnt; }
private int writeString(final DataOutput output, String string, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (string == null) { output.write(ST_NULL); return cnt; } // make sure we never duplicate a string string = stringCache.computeIfAbsent(string, Function.identity()); final int idx = seen.get(string, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { seen.put(string, cnt); output.write(ST_NEW_STRING); output.writeUTF(string); return cnt + 1; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeString(final DataOutput output, String string, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (string == null) { output.write(ST_NULL); return cnt; } // make sure we never duplicate a string string = stringCache.computeIfAbsent(string, Function.identity()); final int idx = seen.get(string, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { seen.put(string, cnt); output.write(ST_NEW_STRING); output.writeUTF(string); return cnt + 1; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeStackElement(final DataOutput output, final StackTraceElement element, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, int cnt) throws IOException { final int idx = seen.get(element, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { output.write(ST_NEW_STACK_ELEMENT_V8); cnt = writeString(output, element.getClassName(), seen, stringCache, cnt); cnt = writeString(output, element.getMethodName(), seen, stringCache, cnt); cnt = writeString(output, element.getFileName(), seen, stringCache, cnt); writePackedInt(output, element.getLineNumber()); seen.put(element, cnt++); return cnt; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeStackElement(final DataOutput output, final StackTraceElement element, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, int cnt) throws IOException { final int idx = seen.get(element, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { output.write(ST_NEW_STACK_ELEMENT_V8); cnt = writeString(output, element.getClassName(), seen, stringCache, cnt); cnt = writeString(output, element.getMethodName(), seen, stringCache, cnt); cnt = writeString(output, element.getFileName(), seen, stringCache, cnt); writePackedInt(output, element.getLineNumber()); seen.put(element, cnt++); return cnt; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
private int writeThrowable(final DataOutput output, final Throwable throwable, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (throwable == null) { output.write(ST_NULL); return cnt; } else { final int idx = seen.get(throwable, - 1); final int distance = cnt - idx; if (idx == - 1 || distance >= 0x4000) { RemoteExceptionCause nested; if (throwable instanceof RemoteExceptionCause) { nested = (RemoteExceptionCause) throwable; } else { seen.put(throwable, cnt); // do not increment yet nested = of(throwable); } return nested.writeToStream(output, seen, stringCache, cnt); // this will increment it } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } } }
private int writeThrowable(final DataOutput output, final Throwable throwable, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (throwable == null) { output.write(ST_NULL); return cnt; } else { final int idx = seen.get(throwable, - 1); final int distance = cnt - idx; if (idx == - 1 || distance >= 0x4000) { RemoteExceptionCause nested; if (throwable instanceof RemoteExceptionCause) { nested = (RemoteExceptionCause) throwable; } else { seen.put(throwable, cnt); // do not increment yet nested = of(throwable); } return nested.writeToStream(output, seen, stringCache, cnt); // this will increment it } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } } }
private int writeToStream(DataOutput output, IdentityIntMap<Object> seen, HashMap<String, String> stringCache, int cnt) throws IOException { // register in cycle map seen.put(this, cnt++); // write the header byte output.writeByte(ST_NEW_EXCEPTION_CAUSE); // first write class name cnt = writeString(output, exceptionClassName, seen, stringCache, cnt); // null or message cnt = writeString(output, getMessage(), seen, stringCache, cnt); // stack trace cnt = writeStackTrace(output, getStackTrace(), seen, stringCache, cnt); // fields cnt = writeFields(output, fields, seen, stringCache, cnt); // caused-by cnt = writeThrowable(output, getCause(), seen, stringCache, cnt); // suppressed final Throwable[] suppressed = getSuppressed(); writePackedInt(output, suppressed.length); for (final Throwable t : suppressed) { cnt = writeThrowable(output, t, seen, stringCache, cnt); } return cnt; }
private int writeToStream(DataOutput output, IdentityIntMap<Object> seen, HashMap<String, String> stringCache, int cnt) throws IOException { // register in cycle map seen.put(this, cnt++); // write the header byte output.writeByte(ST_NEW_EXCEPTION_CAUSE); // first write class name cnt = writeString(output, exceptionClassName, seen, stringCache, cnt); // null or message cnt = writeString(output, getMessage(), seen, stringCache, cnt); // stack trace cnt = writeStackTrace(output, getStackTrace(), seen, stringCache, cnt); // fields cnt = writeFields(output, fields, seen, stringCache, cnt); // caused-by cnt = writeThrowable(output, getCause(), seen, stringCache, cnt); // suppressed final Throwable[] suppressed = getSuppressed(); writePackedInt(output, suppressed.length); for (final Throwable t : suppressed) { cnt = writeThrowable(output, t, seen, stringCache, cnt); } return cnt; }