/** * Write this remote exception cause to the given stream, without using serialization. * * @param output the output stream (must not be {@code null}) * @throws IOException if an error occurs writing the data */ public void writeToStream(DataOutput output) throws IOException { Assert.checkNotNullParam("output", output); writeToStream(output, new IdentityIntMap<Object>(), new HashMap<String,String>(), 0); }
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; } }
/** * Put a value into the map. Any previous mapping is discarded silently. * * @param key the key * @param value the value to store */ public void put(T key, int value) { final Object[] keys = this.keys; final int mask = keys.length - 1; final int[] values = this.values; Object v; int hc = System.identityHashCode(key) & mask; for (int idx = hc;; idx = hc++ & mask) { v = keys[idx]; if (v == null) { keys[idx] = key; values[idx] = value; if (++count > resizeCount) { resize(); } return; } if (v == key) { values[idx] = value; return; } } }
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; }
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; } } }
/** * Write this remote exception cause to the given stream, without using serialization. * * @param output the output stream (must not be {@code null}) * @throws IOException if an error occurs writing the data */ public void writeToStream(DataOutput output) throws IOException { Assert.checkNotNullParam("output", output); writeToStream(output, new IdentityIntMap<Object>(), new HashMap<String,String>(), 0); }
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; }
/** * Put a value into the map. Any previous mapping is discarded silently. * * @param key the key * @param value the value to store */ public void put(T key, int value) { final Object[] keys = this.keys; final int mask = keys.length - 1; final int[] values = this.values; Object v; int hc = System.identityHashCode(key) & mask; for (int idx = hc;; idx = hc++ & mask) { v = keys[idx]; if (v == null) { keys[idx] = key; values[idx] = value; if (++count > resizeCount) { resize(); } return; } if (v == key) { values[idx] = value; return; } } }
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; } }
/** * Write this remote exception cause to the given stream, without using serialization. * * @param output the output stream (must not be {@code null}) * @throws IOException if an error occurs writing the data */ public void writeToStream(DataOutput output) throws IOException { Assert.checkNotNullParam("output", output); writeToStream(output, new IdentityIntMap<Object>(), new HashMap<String,String>(), 0); }
/** * Put a value into the map. Any previous mapping is discarded silently. * * @param key the key * @param value the value to store */ public void put(T key, int value) { final Object[] keys = this.keys; final int mask = keys.length - 1; final int[] values = this.values; Object v; int hc = System.identityHashCode(key) & mask; for (int idx = hc;; idx = hc++ & mask) { v = keys[idx]; if (v == null) { keys[idx] = key; values[idx] = value; if (++count > resizeCount) { resize(); } return; } if (v == key) { values[idx] = value; return; } } }
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 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 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 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; } }