Skip to content

Commit

Permalink
(#28) Added setBinaryStream
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Apr 17, 2019
1 parent be92434 commit bf84552
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit bf84552

Please sign in to comment.