| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.util.StaticUtils; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import static org.opends.server.loggers.debug.DebugLogger.getTracer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | /** |
| | | * An ASN1Writer implementation that outputs to an outputstream. |
| | | */ |
| | | final class ASN1OutputStreamWriter implements ASN1Writer |
| | | { |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private final OutputStream rootStream; |
| | | private final ArrayList<ByteSequenceOutputStream> streamStack; |
| | |
| | | { |
| | | writeLength(1); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 1, intValue)); |
| | | } |
| | |
| | | writeLength(2); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 2, intValue)); |
| | | } |
| | |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 3, intValue)); |
| | | } |
| | |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 4, intValue)); |
| | | } |
| | |
| | | { |
| | | writeLength(1); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 1, longValue)); |
| | | } |
| | |
| | | writeLength(2); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 2, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 3, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 4, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 5, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 6, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 7, longValue)); |
| | | } |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", |
| | | type, 8, longValue)); |
| | | } |
| | |
| | | writeLength(1); |
| | | out.write(booleanValue ? BOOLEAN_VALUE_TRUE : BOOLEAN_VALUE_FALSE); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", |
| | | type, 1, String.valueOf(booleanValue))); |
| | | } |
| | |
| | | out.write(type); |
| | | writeLength(0); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 NULL(type=0x%x, length=%d)", |
| | | type, 0)); |
| | | } |
| | |
| | | writeLength(length); |
| | | out.write(value, offset, length); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", |
| | | type, length)); |
| | | } |
| | |
| | | writeLength(bytes.length); |
| | | out.write(bytes); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d, " + |
| | | "value=%s)", type, bytes.length, value)); |
| | | } |
| | |
| | | writeLength(value.length()); |
| | | value.copyTo(out); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", |
| | | type, value.length())); |
| | | } |
| | |
| | | out = childStream; |
| | | } |
| | | /* |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 START SEQUENCE(type=0x%x)", |
| | | type)); |
| | | } |
| | |
| | | writeLength(childStream.length()); |
| | | childStream.writeTo(parentStream); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("WRITE ASN.1 END SEQUENCE(length=%d)", |
| | | childStream.length())); |
| | | } |