Java Code Examples for com.mysql.cj.util.StringUtils#escapeblockFast()

The following examples show how to use com.mysql.cj.util.StringUtils#escapeblockFast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientPreparedQueryBindings.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setBlob(int parameterIndex, Blob x) {
    if (x == null) {
        setNull(parameterIndex);
    } else {
        try {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();

            bytesOut.write('\'');
            StringUtils.escapeblockFast(x.getBytes(1, (int) x.length()), bytesOut, (int) x.length(),
                    this.session.getServerSession().useAnsiQuotedIdentifiers());
            bytesOut.write('\'');

            setValue(parameterIndex, bytesOut.toByteArray(), MysqlType.BLOB);
        } catch (Throwable t) {
            throw ExceptionFactory.createException(t.getMessage(), t);
        }
    }
}
 
Example 2
Source File: ClientPreparedQueryBindings.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setBlob(int parameterIndex, Blob x) {
    if (x == null) {
        setNull(parameterIndex);
    } else {
        try {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();

            bytesOut.write('\'');
            StringUtils.escapeblockFast(x.getBytes(1, (int) x.length()), bytesOut, (int) x.length(),
                    this.session.getServerSession().useAnsiQuotedIdentifiers());
            bytesOut.write('\'');

            setValue(parameterIndex, bytesOut.toByteArray(), MysqlType.BLOB);
        } catch (Throwable t) {
            throw ExceptionFactory.createException(t.getMessage(), t);
        }
    }
}
 
Example 3
Source File: AbstractPreparedQuery.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected final byte[] streamToBytes(InputStream in, boolean escape, int streamLength, boolean useLength) {
    in.mark(Integer.MAX_VALUE); // we may need to read this same stream several times, so we need to reset it at the end.
    try {
        if (this.streamConvertBuf == null) {
            this.streamConvertBuf = new byte[4096];
        }
        if (streamLength == -1) {
            useLength = false;
        }

        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();

        int bc = useLength ? readblock(in, this.streamConvertBuf, streamLength) : readblock(in, this.streamConvertBuf);

        int lengthLeftToRead = streamLength - bc;

        if (escape) {
            bytesOut.write('_');
            bytesOut.write('b');
            bytesOut.write('i');
            bytesOut.write('n');
            bytesOut.write('a');
            bytesOut.write('r');
            bytesOut.write('y');
            bytesOut.write('\'');
        }

        while (bc > 0) {
            if (escape) {
                StringUtils.escapeblockFast(this.streamConvertBuf, bytesOut, bc, this.usingAnsiMode);
            } else {
                bytesOut.write(this.streamConvertBuf, 0, bc);
            }

            if (useLength) {
                bc = readblock(in, this.streamConvertBuf, lengthLeftToRead);

                if (bc > 0) {
                    lengthLeftToRead -= bc;
                }
            } else {
                bc = readblock(in, this.streamConvertBuf);
            }
        }

        if (escape) {
            bytesOut.write('\'');
        }

        return bytesOut.toByteArray();
    } finally {
        try {
            in.reset();
        } catch (IOException e) {
        }
        if (this.autoClosePStmtStreams.getValue()) {
            try {
                in.close();
            } catch (IOException ioEx) {
            }

            in = null;
        }
    }
}
 
Example 4
Source File: AbstractPreparedQuery.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
protected final byte[] streamToBytes(InputStream in, boolean escape, int streamLength, boolean useLength) {
    in.mark(Integer.MAX_VALUE); // we may need to read this same stream several times, so we need to reset it at the end.
    try {
        if (this.streamConvertBuf == null) {
            this.streamConvertBuf = new byte[4096];
        }
        if (streamLength == -1) {
            useLength = false;
        }

        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();

        int bc = useLength ? readblock(in, this.streamConvertBuf, streamLength) : readblock(in, this.streamConvertBuf);

        int lengthLeftToRead = streamLength - bc;

        if (escape) {
            bytesOut.write('_');
            bytesOut.write('b');
            bytesOut.write('i');
            bytesOut.write('n');
            bytesOut.write('a');
            bytesOut.write('r');
            bytesOut.write('y');
            bytesOut.write('\'');
        }

        while (bc > 0) {
            if (escape) {
                StringUtils.escapeblockFast(this.streamConvertBuf, bytesOut, bc, this.usingAnsiMode);
            } else {
                bytesOut.write(this.streamConvertBuf, 0, bc);
            }

            if (useLength) {
                bc = readblock(in, this.streamConvertBuf, lengthLeftToRead);

                if (bc > 0) {
                    lengthLeftToRead -= bc;
                }
            } else {
                bc = readblock(in, this.streamConvertBuf);
            }
        }

        if (escape) {
            bytesOut.write('\'');
        }

        return bytesOut.toByteArray();
    } finally {
        try {
            in.reset();
        } catch (IOException e) {
        }
        if (this.autoClosePStmtStreams.getValue()) {
            try {
                in.close();
            } catch (IOException ioEx) {
            }

            in = null;
        }
    }
}