Пример #1
0
  public void runStringTest(int length) throws IOException {
    Output write = new Output(1024, -1);
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < length; i++) buffer.append((char) i);

    String value = buffer.toString();
    write.writeString(value);
    write.writeString(value);
    Input read = new Input(write.toBytes());
    assertEquals(value, read.readString());
    assertEquals(value, read.readStringBuilder().toString());

    write.clear();
    write.writeString(buffer);
    write.writeString(buffer);
    read = new Input(write.toBytes());
    assertEquals(value, read.readStringBuilder().toString());
    assertEquals(value, read.readString());

    if (length <= 127) {
      write.clear();
      write.writeAscii(value);
      write.writeAscii(value);
      read = new Input(write.toBytes());
      assertEquals(value, read.readStringBuilder().toString());
      assertEquals(value, read.readString());
    }
  }
Пример #2
0
  public void runStringTest(Output write) throws IOException {
    String value1 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz\n1234567890\t\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*";
    String value2 = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";

    write.writeString("");
    write.writeString("1");
    write.writeString("22");
    write.writeString("uno");
    write.writeString("dos");
    write.writeString("tres");
    write.writeString(null);
    write.writeString(value1);
    write.writeString(value2);
    for (int i = 0; i < 127; i++) write.writeString(String.valueOf((char) i));
    for (int i = 0; i < 127; i++) write.writeString(String.valueOf((char) i) + "abc");

    Input read = new Input(write.toBytes());
    assertEquals("", read.readString());
    assertEquals("1", read.readString());
    assertEquals("22", read.readString());
    assertEquals("uno", read.readString());
    assertEquals("dos", read.readString());
    assertEquals("tres", read.readString());
    assertEquals(null, read.readString());
    assertEquals(value1, read.readString());
    assertEquals(value2, read.readString());
    for (int i = 0; i < 127; i++) assertEquals(String.valueOf((char) i), read.readString());
    for (int i = 0; i < 127; i++) assertEquals(String.valueOf((char) i) + "abc", read.readString());

    read.rewind();
    assertEquals("", read.readStringBuilder().toString());
    assertEquals("1", read.readStringBuilder().toString());
    assertEquals("22", read.readStringBuilder().toString());
    assertEquals("uno", read.readStringBuilder().toString());
    assertEquals("dos", read.readStringBuilder().toString());
    assertEquals("tres", read.readStringBuilder().toString());
    assertEquals(null, read.readStringBuilder());
    assertEquals(value1, read.readStringBuilder().toString());
    assertEquals(value2, read.readStringBuilder().toString());
    for (int i = 0; i < 127; i++)
      assertEquals(String.valueOf((char) i), read.readStringBuilder().toString());
    for (int i = 0; i < 127; i++)
      assertEquals(String.valueOf((char) i) + "abc", read.readStringBuilder().toString());
  }
Пример #3
0
 public StringBuilder read(Kryo kryo, Input input, Class<StringBuilder> type) {
   return input.readStringBuilder();
 }