@Test(expected = IllegalArgumentException.class) public void testEncodedValueContainsTerm() { DataType<byte[]> type = new TerminatedWrapper<byte[]>(new RawBytes(), "foo"); PositionedByteRange buff = new SimplePositionedByteRange(16); type.encode(buff, Bytes.toBytes("hello foobar!")); }
@Override public int encode(PositionedByteRange dst, T val) { final int start = dst.getPosition(); int written = wrapped.encode(dst, val); PositionedByteRange b = dst.shallowCopy(); b.setLength(dst.getPosition()); b.setPosition(start); if (-1 != terminatorPosition(b)) { dst.setPosition(start); throw new IllegalArgumentException("Encoded value contains terminator sequence."); } dst.put(term); return written + term.length; }
TerminatedWrapper implements DataType<T> { @Override public int encode(PositionedByteRange dst, T val) { final int start = dst.getPosition(); int written = wrapped.encode(dst, val); PositionedByteRange b = dst.shallowCopy(); b.setLength(dst.getPosition()); b.setPosition(start); if (-1 != terminatorPosition(b)) { dst.setPosition(start); throw new IllegalArgumentException("Encoded value contains terminator sequence."); } dst.put(term); return written + term.length; } }
TerminatedWrapper implements DataType<T> { @Override public int encode(PositionedByteRange dst, T val) { final int start = dst.getPosition(); int written = wrapped.encode(dst, val); PositionedByteRange b = dst.shallowCopy(); b.setLength(dst.getPosition()); b.setPosition(start); if (-1 != terminatorPosition(b)) { dst.setPosition(start); throw new IllegalArgumentException("Encoded value contains terminator sequence."); } dst.put(term); return written + term.length; } TerminatedWrapper(DataType<T> wrapped, byte[] term);  TerminatedWrapper(DataType<T> wrapped, String term); }
TerminatedWrapper implements DataType<T> { @Override public int encode(PositionedByteRange dst, T val) { final int start = dst.getPosition(); int written = wrapped.encode(dst, val); PositionedByteRange b = dst.shallowCopy(); b.setLength(dst.getPosition()); b.setPosition(start); if (-1 != terminatorPosition(b)) { dst.setPosition(start); throw new IllegalArgumentException("Encoded value contains terminator sequence."); } dst.put(term); return written + term.length; } TerminatedWrapper(DataType<T> wrapped, byte[] term);  TerminatedWrapper(DataType<T> wrapped, String term); @Override boolean isOrderPreserving(); @Override Order getOrder(); @Override boolean isNullable(); @Override boolean isSkippable(); @Override int encodedLength(T val); @Override Class<T> encodedClass(); @Override int skip(PositionedByteRange src); @Override T decode(PositionedByteRange src); @Override int encode(PositionedByteRange dst, T val); }
TerminatedWrapper implements DataType<T> { @Override public int encode(PositionedByteRange dst, T val) { final int start = dst.getPosition(); int written = wrapped.encode(dst, val); PositionedByteRange b = dst.shallowCopy(); b.setLength(dst.getPosition()); b.setPosition(start); if (-1 != terminatorPosition(b)) { dst.setPosition(start); throw new IllegalArgumentException("Encoded value contains terminator sequence."); } dst.put(term); return written + term.length; } TerminatedWrapper(DataType<T> wrapped, byte[] term);  TerminatedWrapper(DataType<T> wrapped, String term); @Override boolean isOrderPreserving(); @Override Order getOrder(); @Override boolean isNullable(); @Override boolean isSkippable(); @Override int encodedLength(T val); @Override Class<T> encodedClass(); @Override int skip(PositionedByteRange src); @Override T decode(PositionedByteRange src); @Override int encode(PositionedByteRange dst, T val);  }