Ejemplo n.º 1
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());
  }
Ejemplo n.º 2
0
 /**
  * Sets a new InputStream. The position and total are reset, discarding any buffered bytes.
  *
  * @param inputStream May be null.
  */
 public void setInputStream(InputStream inputStream) {
   this.inputStream = inputStream;
   limit = 0;
   rewind();
 }