Skip to content

Commit

Permalink
#32 All unimplemented methods in Blob raise exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhannes committed Aug 16, 2016
1 parent 5c1a7fe commit b375480
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/main/java/org/sqldroid/SQLDroidBlob.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.sqldroid;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;

public class SQLDroidBlob implements Blob {

Expand All @@ -15,12 +17,25 @@ public SQLDroidBlob(byte [] b) {

@Override
public InputStream getBinaryStream() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return null;
return getBinaryStream(0, b.length);
}

@Override
public InputStream getBinaryStream(long pos, long length) throws SQLException {
return new ByteArrayInputStream(b, (int)pos, (int)length);
}

@Override
public byte[] getBytes(long pos, int length) throws SQLException {
if (pos < 0) {
throw new SQLException("pos must be > 0");
}
if (length < 0) {
throw new SQLException("length must be > 0");
}
if (pos > 0 || length < b.length) {
throw new UnsupportedOperationException("getBytes implementation only supports return full byte array");
}
return b;
}

Expand All @@ -31,55 +46,40 @@ public long length() throws SQLException {

@Override
public long position(Blob pattern, long start) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return 0;
return position(pattern.getBytes(0, (int) pattern.length()), start);
}

@Override
public long position(byte[] pattern, long start) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return 0;
throw new SQLFeatureNotSupportedException("position not supported");
}

@Override
public OutputStream setBinaryStream(long pos) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return null;
throw new SQLFeatureNotSupportedException("setBinaryStream not supported");
}

@Override
public int setBytes(long pos, byte[] theBytes) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return 0;
return setBytes(pos, theBytes, 0, theBytes.length);
}

@Override
public int setBytes(long pos, byte[] theBytes, int offset, int len)
throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
return 0;
public int setBytes(long pos, byte[] theBytes, int offset, int len) throws SQLException {
throw new SQLFeatureNotSupportedException("setBytes not supported");
}

@Override
public void truncate(long len) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());

throw new SQLFeatureNotSupportedException("truncate not supported");
}

@Override
public void free() throws SQLException {
// TODO Auto-generated method stub

}

@Override
public InputStream getBinaryStream(long pos, long length)
throws SQLException {
// TODO Auto-generated method stub
return null;
throw new SQLFeatureNotSupportedException("free not supported");
}

/** Print the length of the blob along with the first 10 characters.
/** Print the length of the blob along with the first 10 characters.
* @see java.lang.Object#toString()
*/
@Override
Expand Down

0 comments on commit b375480

Please sign in to comment.