public void readWithKnownLength(DataInput in, int len) throws IOException {
    ensureCapacity(len);
    in.readFully(bytes, 0, len);
    length = len;
    textLength = -1;
  }
@Test
  public void testReadWithKnownLength() throws IOException {
    String line = "hello world";
    byte[] inputBytes = line.getBytes(StandardCharsets.UTF_8);
    DataInputBuffer in = new DataInputBuffer();
    Text text = new Text();

    in.reset(inputBytes, inputBytes.length);
    text.readWithKnownLength(in, 5);
    assertEquals("hello", text.toString());
    assertEquals(5, text.getTextLength());

    // Read longer length, make sure it lengthens
    in.reset(inputBytes, inputBytes.length);
    text.readWithKnownLength(in, 7);
    assertEquals("hello w", text.toString());
    assertEquals(7, text.getTextLength());

    // Read shorter length, make sure it shortens
    in.reset(inputBytes, inputBytes.length);
    text.readWithKnownLength(in, 2);
    assertEquals("he", text.toString());
    assertEquals(2, text.getTextLength());
  }