DataExpressionSource extends Source { @Override protected byte[] getData(final BigInteger offset, final BigInteger length) { checkNotNegative(offset, "offset"); final byte[] data = getValue(); if (checkNotNegative(length, "length").add(offset).compareTo(BigInteger.valueOf(data.length)) > 0) { throw new IllegalStateException(format("Data to read is not available ([offset=%d;length=%d;source=%s).", offset, length, this)); } final byte[] outputData = new byte[length.intValueExact()]; System.arraycopy(data, offset.intValueExact(), outputData, 0, outputData.length); return outputData; } DataExpressionSource(final ValueExpression dataExpression, final int index, final ParseState parseState, final Encoding encoding); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); final ValueExpression dataExpression; final int index; final ParseState parseState; final Encoding encoding; }
@Test public void indexOutOfBounds() { thrown.expect(IllegalStateException.class); thrown.expectMessage("ValueExpression dataExpression yields 1 result(s) (expected at least 2)."); final Optional<ParseState> result = setupResult(); final DataExpressionSource source = new DataExpressionSource(ref("a"), 1, result.get(), enc()); source.getData(ZERO, BigInteger.valueOf(4)); }