StringData extends DataType { @Override public String toString() { return "StringData{" + "paddingType=" + paddingType + ", charset=" + charset + '}'; } StringData(ByteBuffer bb); @Override Object fillData(ByteBuffer buffer, int[] dimensions, HdfFileChannel hdfFc); PaddingType getPaddingType(); StringPaddingHandler getStringPaddingHandler(); Charset getCharset(); @Override Class<?> getJavaType(); @Override String toString();  }
@Test void testNullTerminated() { StringPaddingHandler nullTerminated = new StringData.NullTerminated(); ByteBuffer byteBuffer = ByteBuffer.allocate(20); byteBuffer.put("hello".getBytes(US_ASCII)); byteBuffer.put(Constants.NULL); byteBuffer.put("again".getBytes(US_ASCII)); byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(20)); nullTerminated.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(5)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("hello")); }
@Test void testNullTerminatedWithFullBuffer() { StringPaddingHandler nullTerminated = new StringData.NullTerminated(); ByteBuffer byteBuffer = ByteBuffer.allocate(5); byteBuffer.put("hello".getBytes(US_ASCII)); byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(5)); nullTerminated.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(5)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("hello")); }
@Test void testNullPadded() { StringPaddingHandler nullPadded = new NullPadded(); ByteBuffer byteBuffer = ByteBuffer.allocate(20); byteBuffer.put("hello".getBytes(US_ASCII)); byteBuffer.put(Constants.NULL); byteBuffer.put("again".getBytes(US_ASCII)); byteBuffer.put(Constants.NULL); byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(20)); nullPadded.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(11)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("hello" + NULL_AS_CHAR + "again")); }
@Test void testSpacePadded() { StringPaddingHandler spacePadded = new SpacePadded(); ByteBuffer byteBuffer = ByteBuffer.allocate(20); byteBuffer.put("hello again ".getBytes(US_ASCII)); byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(20)); spacePadded.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(11)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("hello again")); }
@Test void testNullPaddedEmptyString() { StringPaddingHandler nullPadded = new NullPadded(); ByteBuffer byteBuffer = ByteBuffer.allocate(4); for (int i = 0; i < byteBuffer.capacity(); i++) { byteBuffer.put(Constants.NULL); } byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(4)); nullPadded.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(0)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("")); }
@Test void testSpacePaddedEmptyString() { StringPaddingHandler spacePadded = new SpacePadded(); ByteBuffer byteBuffer = ByteBuffer.allocate(4); byteBuffer.put(" ".getBytes(US_ASCII)); byteBuffer.rewind(); assertThat(byteBuffer.limit(), is(4)); spacePadded.setBufferLimit(byteBuffer); assertThat(byteBuffer.limit(), is(0)); assertThat(US_ASCII.decode(byteBuffer).toString(), is("")); }