diff --git a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java index 3502839..7a7a4eb 100644 --- a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java +++ b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java @@ -60,6 +60,21 @@ public long position(final Blob pattern, final long start) throws SQLException { return -1; } + @Override + public OutputStream setBinaryStream(final long pos) { + if(lobUtils.fitsInInt(pos)){ + return new OutputStream() { + int index = (int) lobUtils.applyOffset(pos); + + @Override + public void write(final int byteToWrite) { + content[index++] = (byte) byteToWrite; + } + }; + } + return null; + } + @Override public int setBytes(final long pos, final byte[] bytes) { final long positionWithOffset = lobUtils.applyOffset(pos); @@ -80,11 +95,6 @@ public int setBytes(final long pos, final byte[] bytes, final int offset, final return 0; } - @Override - public OutputStream setBinaryStream(final long pos) { - return null; - } - @Override public void truncate(final long len) { if(lobUtils.fitsInInt(len)){ diff --git a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java index 427dfd0..5aa564f 100644 --- a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java +++ b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.sql.Blob; import java.sql.SQLException; @@ -175,4 +176,20 @@ public void testGetLimitedBinaryStream() throws IOException { //THEN assertEquals(IOUtils.toByteArray(limitedBinarySteam), expectedStreamContent); } + + @Test + public void testSetBinaryStream() throws IOException { + + //GIVEN + final byte[] expectedBlobContent = "Beam us Up, Scotty".getBytes(); + citrusBlob.setBytes(1, sampleBytes); + + //WHEN + final OutputStream blobOutputStream = citrusBlob.setBinaryStream(6); + blobOutputStream.write("us".getBytes()); + + //THEN + final InputStream blobContent = citrusBlob.getBinaryStream(); + assertEquals(IOUtils.toByteArray(blobContent), expectedBlobContent); + } } \ No newline at end of file