private static void unlog(final FieldType<?> fieldType, final StringBuilder buf) { if (fieldType.isIndentingAndOutdenting()) { buf.insert(0, "< "); } decrementDebugLevel(); if (fieldType.isIndentingAndOutdenting()) { buf.insert(0, spaces(currentDebugLevel())); LOG.debug(buf.toString()); } }
private static void decrementDebugLevel() { final int[] indentLevel = debugIndent(); indentLevel[0] -= 2; }
public final <Q> Q[] readArray(final DataInputExtended input, final Class<Q> elementType) throws IOException { final DataInputStream inputStream = input.getDataInputStream(); final byte fieldTypeIdxAndNullability = inputStream.readByte(); final boolean isNull = fieldTypeIdxAndNullability >= NULL_BIT; final byte fieldTypeIdx = (byte) (fieldTypeIdxAndNullability - (isNull ? NULL_BIT : 0)); try { final FieldType<?> fieldType = FieldType.get(fieldTypeIdx); if (fieldType.checksStream() && fieldType != this) { throw new IllegalStateException("Mismatch in stream: expected " + this + " but got " + fieldType); } if (isNull && LOG.isDebugEnabled()) { // only log if reading a null; otherwise actual value read // logged later log(this, new StringBuilder().append("(null)")); } if (isNull) { return null; } else { return doReadArray(input, elementType); } } finally { if (isNull && LOG.isDebugEnabled()) { // only unlog if reading a null unlog(this); } } }
public final T read(final DataInputExtended input) throws IOException { final DataInputStream inputStream = input.getDataInputStream(); final byte fieldTypeIdxAndNullability = inputStream.readByte(); final boolean isNull = fieldTypeIdxAndNullability >= NULL_BIT; final byte fieldTypeIdx = (byte) (fieldTypeIdxAndNullability - (isNull ? NULL_BIT : 0)); try { final FieldType<?> fieldType = FieldType.get(fieldTypeIdx); if (fieldType == null || (fieldType.checksStream() && fieldType != this)) { throw new IllegalStateException("Mismatch in stream: expected " + this + " but got " + fieldType + " (" + fieldTypeIdx + ")"); } if (isNull && LOG.isDebugEnabled()) { // only log if reading a null; otherwise actual value read // logged later log(this, new StringBuilder().append("(null)")); } if (isNull) { return null; } else { return doRead(input); } } finally { if (isNull && LOG.isDebugEnabled()) { // only unlog if reading a null unlog(this); } } }
private static void log(final FieldType<?> fieldType, final StringBuilder buf) { buf.insert(0, ": "); buf.insert(0, fieldType); if (fieldType.isIndentingAndOutdenting()) { buf.insert(0, "> "); } buf.insert(0, spaces(currentDebugLevel())); incrementDebugLevel(); LOG.debug(buf.toString()); }
public final void write(final DataOutputExtended output, final T value) throws IOException { byte fieldTypeIdxAndNullability = getIdx(); final boolean isNull = value == null; if (isNull) { // set high order bit fieldTypeIdxAndNullability += NULL_BIT; } try { final DataOutputStream outputStream = output.getDataOutputStream(); outputStream.write(fieldTypeIdxAndNullability); if (isNull && LOG.isDebugEnabled()) { // only log if writing a null; otherwise actual value logged // later log(this, new StringBuilder().append("(null)")); } if (!isNull) { doWrite(output, value); } } finally { if (isNull && LOG.isDebugEnabled()) { // only unlog if writing a null unlog(this); } } }
@Override public String toString() { return getCls().getSimpleName(); }
private static int currentDebugLevel() { return debugIndent()[0]; }
private static void incrementDebugLevel() { final int[] indentLevel = debugIndent(); indentLevel[0] += 2; }