mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-11 12:14:21 +01:00
test(jdbc): implements setAsciiStream, setBinaryStream methods (int, InputStream)
This commit is contained in:
@@ -461,12 +461,51 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
|
||||
|
||||
@Override
|
||||
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
|
||||
// TODO
|
||||
requireNonNull(this.statement);
|
||||
if (x == null) {
|
||||
this.statement.bindNull(parameterIndex);
|
||||
return;
|
||||
}
|
||||
byte[] data = readBytes(x);
|
||||
String ascii = new String(data, StandardCharsets.US_ASCII);
|
||||
this.statement.bindText(parameterIndex, ascii);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
|
||||
// TODO
|
||||
requireNonNull(this.statement);
|
||||
if (x == null) {
|
||||
this.statement.bindNull(parameterIndex);
|
||||
return;
|
||||
}
|
||||
byte[] data = readBytes(x);
|
||||
this.statement.bindBlob(parameterIndex, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all bytes from the given input stream.
|
||||
*
|
||||
* @param x the input stream to read
|
||||
* @return a byte array containing the data
|
||||
* @throws SQLException if an I/O error occurs while reading
|
||||
*/
|
||||
private byte[] readBytes(InputStream x) throws SQLException {
|
||||
try {
|
||||
int firstByte = x.read();
|
||||
if (firstByte == -1) {
|
||||
return new byte[0];
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write(firstByte);
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
while ((bytesRead = x.read(buffer)) > 0) {
|
||||
baos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Error reading InputStream", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user