private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
@Test(dataProvider = "ListOfStrings") public void testEncodingListOfString(List<String> strings, String expected) throws IOException { final String collapsed = BCF2Utils.collapseStringList(strings); Assert.assertEquals(collapsed, expected); Assert.assertEquals(BCF2Utils.explodeStringList(collapsed), strings); }
@Test(dataProvider = "CollapseExpandTest") public void testCollapseExpandTest(final List<String> in, final String expectedCollapsed, final boolean isCollapsed) { final String actualCollapsed = BCF2Utils.collapseStringList(in); Assert.assertEquals(actualCollapsed, expectedCollapsed); Assert.assertEquals(BCF2Utils.isCollapsedString(actualCollapsed), isCollapsed); if ( isCollapsed ) Assert.assertEquals(BCF2Utils.explodeStringList(actualCollapsed), in); }