Ejemplo n.º 1
0
 final void writeLongInt(int i) throws SQLException {
   ensureCapacity(3);
   byte[] b = this.byteBuffer;
   b[this.position++] = (byte) (i & 0xff);
   b[this.position++] = (byte) (i >>> 8);
   b[this.position++] = (byte) (i >>> 16);
 }
Ejemplo n.º 2
0
 // Write a String using the specified character encoding
 final void writeLenBytes(byte[] b) throws SQLException {
   int len = b.length;
   ensureCapacity(len + 9);
   writeFieldLength(len);
   System.arraycopy(b, 0, this.byteBuffer, this.position, len);
   this.position += len;
 }
Ejemplo n.º 3
0
  // Write a String using the specified character encoding
  final void writeLenString(
      String s,
      String encoding,
      String serverEncoding,
      SingleByteCharsetConverter converter,
      boolean parserKnowsUnicode,
      MySQLConnection conn)
      throws UnsupportedEncodingException, SQLException {
    byte[] b = null;

    if (converter != null) {
      b = converter.toBytes(s);
    } else {
      b =
          StringUtils.getBytes(
              s,
              encoding,
              serverEncoding,
              parserKnowsUnicode,
              conn,
              conn.getExceptionInterceptor());
    }

    int len = b.length;
    ensureCapacity(len + 9);
    writeFieldLength(len);
    System.arraycopy(b, 0, this.byteBuffer, this.position, len);
    this.position += len;
  }
Ejemplo n.º 4
0
 final void writeFieldLength(long length) throws SQLException {
   if (length < 251) {
     writeByte((byte) length);
   } else if (length < 65536L) {
     ensureCapacity(3);
     writeByte((byte) 252);
     writeInt((int) length);
   } else if (length < 16777216L) {
     ensureCapacity(4);
     writeByte((byte) 253);
     writeLongInt((int) length);
   } else {
     ensureCapacity(9);
     writeByte((byte) 254);
     writeLongLong(length);
   }
 }
Ejemplo n.º 5
0
  //	 Write null-terminated string in the given encoding
  final void writeString(String s, String encoding, MySQLConnection conn) throws SQLException {
    ensureCapacity((s.length() * 3) + 1);
    try {
      writeStringNoNull(s, encoding, encoding, false, conn);
    } catch (UnsupportedEncodingException ue) {
      throw new SQLException(ue.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
    }

    this.byteBuffer[this.position++] = 0;
  }
Ejemplo n.º 6
0
  final void writeFloat(float f) throws SQLException {
    ensureCapacity(4);

    int i = Float.floatToIntBits(f);
    byte[] b = this.byteBuffer;
    b[this.position++] = (byte) (i & 0xff);
    b[this.position++] = (byte) (i >>> 8);
    b[this.position++] = (byte) (i >>> 16);
    b[this.position++] = (byte) (i >>> 24);
  }
Ejemplo n.º 7
0
  // Write string, with no termination
  final void writeStringNoNull(String s) throws SQLException {
    int len = s.length();
    ensureCapacity(len * 3);
    System.arraycopy(StringUtils.getBytes(s), 0, this.byteBuffer, this.position, len);
    this.position += len;

    // for (int i = 0; i < len; i++)
    // {
    // this.byteBuffer[this.position++] = (byte)s.charAt(i);
    // }
  }
Ejemplo n.º 8
0
 final void writeLongLong(long i) throws SQLException {
   ensureCapacity(8);
   byte[] b = this.byteBuffer;
   b[this.position++] = (byte) (i & 0xff);
   b[this.position++] = (byte) (i >>> 8);
   b[this.position++] = (byte) (i >>> 16);
   b[this.position++] = (byte) (i >>> 24);
   b[this.position++] = (byte) (i >>> 32);
   b[this.position++] = (byte) (i >>> 40);
   b[this.position++] = (byte) (i >>> 48);
   b[this.position++] = (byte) (i >>> 56);
 }
Ejemplo n.º 9
0
  // Write a String using the specified character encoding
  final void writeStringNoNull(
      String s,
      String encoding,
      String serverEncoding,
      boolean parserKnowsUnicode,
      MySQLConnection conn)
      throws UnsupportedEncodingException, SQLException {
    byte[] b =
        StringUtils.getBytes(
            s, encoding, serverEncoding, parserKnowsUnicode, conn, conn.getExceptionInterceptor());

    int len = b.length;
    ensureCapacity(len);
    System.arraycopy(b, 0, this.byteBuffer, this.position, len);
    this.position += len;
  }
Ejemplo n.º 10
0
 // Write null-terminated string
 final void writeString(String s) throws SQLException {
   ensureCapacity((s.length() * 3) + 1);
   writeStringNoNull(s);
   this.byteBuffer[this.position++] = 0;
 }
Ejemplo n.º 11
0
 // Write a byte array with the given offset and length
 final void writeBytesNoNull(byte[] bytes, int offset, int length) throws SQLException {
   ensureCapacity(length);
   System.arraycopy(bytes, offset, this.byteBuffer, this.position, length);
   this.position += length;
 }
Ejemplo n.º 12
0
 // Write a byte array
 public final void writeBytesNoNull(byte[] bytes) throws SQLException {
   int len = bytes.length;
   ensureCapacity(len);
   System.arraycopy(bytes, 0, this.byteBuffer, this.position, len);
   this.position += len;
 }
Ejemplo n.º 13
0
  public final void writeByte(byte b) throws SQLException {
    ensureCapacity(1);

    this.byteBuffer[this.position++] = b;
  }