*/
    private void writeValue(Object val) throws IOException {
        if (val == null) {
            writeByteString("null");
        }
        else if (val instanceof Name) {
            writeName( (Name) val );
        }
        else if (val instanceof Reference) {
            writeReference( (Reference) val );
        }
        else if (val instanceof Boolean) {
            writeBoolean( ((Boolean) val).booleanValue() );
        }
        else if (val instanceof Integer) {
            writeInteger( ((Integer) val).intValue() );
        }
        else if (val instanceof Long) {
            writeLong( ((Long) val).longValue() );
        }
        else if (val instanceof Number) {
            writeReal( (Number) val );
        }
        else if (val instanceof String) {
            logger.severe("Found invalid java.lang.String being written out: "
                + val.toString());
            throw new IllegalArgumentException(
                "invalid type of java.lang.String. " +
                "Should use LiteralStringObject or HexStringObject");
        }
        else if (val instanceof LiteralStringObject) {
            writeLiteralString((LiteralStringObject) val);
        }
        else if (val instanceof HexStringObject) {
            writeHexString((HexStringObject) val);
        }
        else if (val instanceof Vector) {
            writeArray( (Vector) val );
        }
        else if (val instanceof Dictionary) {
            writeDictionary( (Dictionary) val );
        }
        else if (val instanceof Hashtable) {
            writeDictionary( (Hashtable<Object,Object>) val );
        }
        else {
            throw new IllegalArgumentException("unknown value type of: " +
                val.getClass().getName());
        }
    }