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

The following examples show how to use org.apache.activemq.artemis.api.core.SimpleString#writeSimpleString() . 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: UTF8Util.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void writeString(final ByteBuf buffer, final String val) {
   int length = val.length();

   buffer.writeInt(length);

   if (length < 9) {
      // If very small it's more performant to store char by char
      writeAsShorts(buffer, val);
   } else if (length < 0xfff) {
      // Store as UTF - this is quicker than char by char for most strings
      saveUTF(buffer, val);
   } else {
      // Store as SimpleString, since can't store utf > 0xffff in length
      SimpleString.writeSimpleString(buffer, new SimpleString(val));
   }
}
 
Example 2
Source File: TypedPropertiesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testByteBufStringValuePool() {
   final int capacity = 8;
   final int chars = Integer.toString(capacity).length();
   final TypedProperties.StringValue.ByteBufStringValuePool pool = new TypedProperties.StringValue.ByteBufStringValuePool(capacity, chars);
   final int bytes = new SimpleString(Integer.toString(capacity)).sizeof();
   final ByteBuf bb = Unpooled.buffer(bytes, bytes);
   for (int i = 0; i < capacity; i++) {
      final SimpleString s = new SimpleString(Integer.toString(i));
      bb.resetWriterIndex();
      SimpleString.writeSimpleString(bb, s);
      bb.resetReaderIndex();
      final TypedProperties.StringValue expectedPooled = pool.getOrCreate(bb);
      bb.resetReaderIndex();
      Assert.assertSame(expectedPooled, pool.getOrCreate(bb));
      bb.resetReaderIndex();
   }
}
 
Example 3
Source File: SimpleStringTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testByteBufSimpleStringPool() {
   final int capacity = 8;
   final int chars = Integer.toString(capacity).length();
   final SimpleString.ByteBufSimpleStringPool pool = new SimpleString.ByteBufSimpleStringPool(capacity, chars);
   final int bytes = new SimpleString(Integer.toString(capacity)).sizeof();
   final ByteBuf bb = Unpooled.buffer(bytes, bytes);
   for (int i = 0; i < capacity; i++) {
      final SimpleString s = new SimpleString(Integer.toString(i));
      bb.resetWriterIndex();
      SimpleString.writeSimpleString(bb, s);
      bb.resetReaderIndex();
      final SimpleString expectedPooled = pool.getOrCreate(bb);
      bb.resetReaderIndex();
      Assert.assertSame(expectedPooled, pool.getOrCreate(bb));
      bb.resetReaderIndex();
   }
}
 
Example 4
Source File: TypedPropertiesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testByteBufStringValuePoolTooLong() {
   final SimpleString tooLong = new SimpleString("aa");
   final ByteBuf bb = Unpooled.buffer(tooLong.sizeof(), tooLong.sizeof());
   SimpleString.writeSimpleString(bb, tooLong);
   final TypedProperties.StringValue.ByteBufStringValuePool pool = new TypedProperties.StringValue.ByteBufStringValuePool(1, tooLong.length() - 1);
   Assert.assertNotSame(pool.getOrCreate(bb), pool.getOrCreate(bb.resetReaderIndex()));
}
 
Example 5
Source File: SimpleStringTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testByteBufSimpleStringPoolTooLong() {
   final SimpleString tooLong = new SimpleString("aa");
   final ByteBuf bb = Unpooled.buffer(tooLong.sizeof(), tooLong.sizeof());
   SimpleString.writeSimpleString(bb, tooLong);
   final SimpleString.ByteBufSimpleStringPool pool = new SimpleString.ByteBufSimpleStringPool(1, tooLong.length() - 1);
   Assert.assertNotSame(pool.getOrCreate(bb), pool.getOrCreate(bb.resetReaderIndex()));
}
 
Example 6
Source File: TypedProperties.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public void write(final ByteBuf buffer) {
   buffer.writeByte(DataConstants.STRING);
   SimpleString.writeSimpleString(buffer, val);
}
 
Example 7
Source File: ChannelBufferWrapper.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public void writeSimpleString(final SimpleString val) {
   SimpleString.writeSimpleString(buffer, val);
}