Search in sources :

Example 1 with HsqlByteArrayOutputStream

use of org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream in project voltdb by VoltDB.

the class Like method getStartsWith.

private Object getStartsWith() {
    if (iLen == 0) {
        return isBinary ? BinaryData.zeroLengthBinary : "";
    }
    StringBuffer sb = null;
    HsqlByteArrayOutputStream os = null;
    if (isBinary) {
        os = new HsqlByteArrayOutputStream();
    } else {
        sb = new StringBuffer();
    }
    int i = 0;
    for (; i < iLen && wildCardType[i] == 0; i++) {
        if (isBinary) {
            os.writeByte(cLike[i]);
        } else {
            sb.append(cLike[i]);
        }
    }
    if (i == 0) {
        return null;
    }
    return isBinary ? new BinaryData(os.toByteArray(), false) : sb.toString();
}
Also used : BinaryData(org.hsqldb_voltpatches.types.BinaryData) HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream)

Example 2 with HsqlByteArrayOutputStream

use of org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream in project voltdb by VoltDB.

the class TextCache method clearRowImage.

private void clearRowImage(CachedObject row) {
    try {
        int length = row.getStorageSize() - ScriptWriterText.BYTES_LINE_SEP.length;
        rowOut.reset();
        HsqlByteArrayOutputStream out = rowOut.getOutputStream();
        out.fill(' ', length);
        out.write(ScriptWriterText.BYTES_LINE_SEP);
        dataFile.seek(row.getPos());
        dataFile.write(out.getBuffer(), 0, out.size());
    } catch (IOException e) {
        throw Error.runtimeError(ErrorCode.U_S0500, e.getMessage());
    }
}
Also used : IOException(java.io.IOException) HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream)

Example 3 with HsqlByteArrayOutputStream

use of org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream in project voltdb by VoltDB.

the class JDBCPreparedStatement method setBinaryStream.

/** @todo 1.9.0 - implement streaming and remove length limits */
/**
     * Sets the designated parameter to the given input stream, which will have
     * the specified number of bytes.
     * When a very large binary value is input to a <code>LONGVARBINARY</code>
     * parameter, it may be more practical to send it via a
     * <code>java.io.InputStream</code> object. The data will be read from the
     * stream as needed until end-of-file is reached.
     *
     * <P><B>Note:</B> This stream object can either be a standard
     * Java stream object or your own subclass that implements the
     * standard interface.
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x the java input stream which contains the binary parameter value
     * @param length the number of bytes in the stream
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @since JDK 1.6 b86, HSQLDB 1.9.0
     */
public synchronized void setBinaryStream(int parameterIndex, java.io.InputStream x, long length) throws SQLException {
    if (length < 0) {
        throw Util.sqlException(ErrorCode.JDBC_INVALID_ARGUMENT, "length: " + length);
    }
    if (x instanceof BlobInputStream) {
        throw Util.sqlException(ErrorCode.JDBC_INVALID_ARGUMENT, "invalid InputStream");
    }
    checkSetParameterIndex(parameterIndex, true);
    if (parameterTypes[parameterIndex - 1].typeCode == Types.SQL_BLOB) {
        streamLengths[parameterIndex - 1] = length;
        setParameter(parameterIndex, x);
        return;
    }
    try {
        if (length > Integer.MAX_VALUE) {
            String msg = "Maximum Blob input length exceeded: " + length;
            throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
        }
        HsqlByteArrayOutputStream output = new HsqlByteArrayOutputStream(x, (int) length);
        setParameter(parameterIndex, output.toByteArray());
    } catch (IOException e) {
        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, e.toString());
    }
}
Also used : IOException(java.io.IOException) HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream)

Example 4 with HsqlByteArrayOutputStream

use of org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream in project voltdb by VoltDB.

the class JDBCPreparedStatement method setBlobForBinaryParameter.

/**
     * Converts a blob to binary data for non-blob binary parameters.
     */
private void setBlobForBinaryParameter(int parameterIndex, Blob x) throws SQLException {
    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());
        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);
        return;
    }
    checkSetParameterIndex(parameterIndex, true);
    final long length = x.length();
    if (length > Integer.MAX_VALUE) {
        // NOI18N
        String msg = "Maximum Blob input octet length exceeded: " + length;
        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }
    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in, (int) length);
        setParameter(parameterIndex, out.toByteArray());
    } catch (IOException e) {
        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, e.toString());
    }
}
Also used : IOException(java.io.IOException) HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream) InputStream(java.io.InputStream)

Example 5 with HsqlByteArrayOutputStream

use of org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream in project voltdb by VoltDB.

the class LobManager method setChars.

public Result setChars(Session session, long lobID, long offset, char[] chars) {
    if (chars.length == 0) {
        return ResultLob.newLobSetResponse(lobID, 0);
    }
    Object[] data = getLobHeader(session, lobID);
    if (data == null) {
        return Result.newErrorResult(Error.error(ErrorCode.X_0F502));
    }
    long length = ((Long) data[1]).longValue();
    HsqlByteArrayOutputStream os = new HsqlByteArrayOutputStream(chars.length * 2);
    os.write(chars, 0, chars.length);
    Result result = setBytesBA(session, lobID, os.getBuffer(), offset * 2, os.getBuffer().length);
    if (result.isError()) {
        return result;
    }
    if (offset + chars.length > length) {
        result = setLength(session, lobID, offset + chars.length);
        if (result.isError()) {
            return result;
        }
    }
    return ResultLob.newLobSetResponse(lobID, 0);
}
Also used : HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream) Result(org.hsqldb_voltpatches.result.Result)

Aggregations

HsqlByteArrayOutputStream (org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)1 Result (org.hsqldb_voltpatches.result.Result)1 BinaryData (org.hsqldb_voltpatches.types.BinaryData)1