Java Code Examples for org.apache.activemq.artemis.api.core.SimpleString#readSimpleString()

The following examples show how to use org.apache.activemq.artemis.api.core.SimpleString#readSimpleString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypedProperties.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
static StringValue readStringValue(final ByteBuf byteBuf, ByteBufStringValuePool pool) {
   if (pool == null) {
      return new StringValue(SimpleString.readSimpleString(byteBuf));
   } else {
      return pool.getOrCreate(byteBuf);
   }
}
 
Example 2
Source File: SimpleStringTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testOutOfBoundsThrownOnMalformedString() {
   ByteBuf byteBuffer = ByteBufAllocator.DEFAULT.buffer(5);
   byteBuffer.writeInt(Integer.MAX_VALUE);

   Exception e = null;
   try {
      SimpleString.readSimpleString(byteBuffer);
   } catch (IndexOutOfBoundsException iob) {
      e = iob;
   }
   assertTrue(e instanceof IndexOutOfBoundsException);
}
 
Example 3
Source File: TypedProperties.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public synchronized void decode(final ByteBuf buffer,
                                final TypedPropertiesDecoderPools keyValuePools) {
   byte b = buffer.readByte();
   if (b == DataConstants.NULL) {
      properties = null;
      size = 0;
   } else {
      int numHeaders = buffer.readInt();

      //optimize the case of no collisions to avoid any resize (it doubles the map size!!!) when load factor is reached
      properties = new HashMap<>(numHeaders, 1.0f);
      size = 0;

      for (int i = 0; i < numHeaders; i++) {
         final SimpleString key = SimpleString.readSimpleString(buffer, keyValuePools == null ? null : keyValuePools.getPropertyKeysPool());

         byte type = buffer.readByte();

         PropertyValue val;

         switch (type) {
            case NULL: {
               val = NullValue.INSTANCE;
               doPutValue(key, val);
               break;
            }
            case CHAR: {
               val = new CharValue(buffer);
               doPutValue(key, val);
               break;
            }
            case BOOLEAN: {
               val = BooleanValue.of(buffer.readBoolean());
               doPutValue(key, val);
               break;
            }
            case BYTE: {
               val = ByteValue.valueOf(buffer.readByte());
               doPutValue(key, val);
               break;
            }
            case BYTES: {
               val = new BytesValue(buffer);
               doPutValue(key, val);
               break;
            }
            case SHORT: {
               val = new ShortValue(buffer);
               doPutValue(key, val);
               break;
            }
            case INT: {
               val = new IntValue(buffer);
               doPutValue(key, val);
               break;
            }
            case LONG: {
               val = new LongValue(buffer);
               doPutValue(key, val);
               break;
            }
            case FLOAT: {
               val = new FloatValue(buffer);
               doPutValue(key, val);
               break;
            }
            case DOUBLE: {
               val = new DoubleValue(buffer);
               doPutValue(key, val);
               break;
            }
            case STRING: {
               val = StringValue.readStringValue(buffer, keyValuePools == null ? null : keyValuePools.getPropertyValuesPool());
               doPutValue(key, val);
               break;
            }
            default: {
               throw ActiveMQUtilBundle.BUNDLE.invalidType(type);
            }
         }
      }
   }
}
 
Example 4
Source File: TypedProperties.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected StringValue create(final ByteBuf byteBuf, final int length) {
   return new StringValue(SimpleString.readSimpleString(byteBuf, length));
}
 
Example 5
Source File: ChannelBufferWrapper.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleString readSimpleString() {
   return SimpleString.readSimpleString(buffer);
}