~ubuntu-branches/ubuntu/trusty/mysql-connector-java/trusty

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/Buffer.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Miguel Landaeta
  • Date: 2013-07-02 17:07:51 UTC
  • mfrom: (1.1.8) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130702170751-f4rszjabxg0391fr
Tags: 5.1.25-1
* New upstream release
* Refreshed the patches
* Added a patch to build with one JDK and removed the build
  dependency on java-gcj-compat-dev
* Updated Standards-Version to 3.9.4 (no changes)
* Use canonical URLs for the Vcs-* fields
* debian/rules: Improved the clean target to allow rebuilds
* Updated the watch file
* Renamed debian/README.Debian-source to README.source

[ Miguel Landaeta ] 
* Fix FTBFS with OpenJDK 7 (Closes: #706668)
* Remove Michael Koch from Uploaders list.
  Thanks for your work on this package. (Closes: #654122).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
 
2
 Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
3
3
 
4
4
 
5
5
  The MySQL Connector/J is licensed under the terms of the GPLv2
50
50
 
51
51
        protected boolean wasMultiPacket = false;
52
52
 
53
 
        Buffer(byte[] buf) {
 
53
        public Buffer(byte[] buf) {
54
54
                this.byteBuffer = buf;
55
55
                setBufLength(buf.length);
56
56
        }
190
190
                return this.byteBuffer;
191
191
        }
192
192
 
193
 
        int getBufLength() {
 
193
        public int getBufLength() {
194
194
                return this.bufLength;
195
195
        }
196
196
 
246
246
                return ((getBufLength() < 9) && ((this.byteBuffer[0] & 0xff) == 254));
247
247
        }
248
248
 
 
249
        final boolean isAuthMethodSwitchRequestPacket() {
 
250
                return ((this.byteBuffer[0] & 0xff) == 254);
 
251
        }
 
252
 
 
253
        final boolean isOKPacket() {
 
254
                return ((this.byteBuffer[0] & 0xff) == 0);
 
255
        }
 
256
 
 
257
        final boolean isRawPacket() {
 
258
                return ((this.byteBuffer[0] & 0xff) == 1);
 
259
        }
 
260
 
249
261
        final long newReadLength() {
250
262
                int sw = this.byteBuffer[this.position++] & 0xff;
251
263
 
407
419
        // To avoid alloc'ing a new byte array, we
408
420
        // do this by hand, rather than calling getNullTerminatedBytes()
409
421
        //
410
 
        final String readString() {
 
422
        public final String readString() {
411
423
                int i = this.position;
412
424
                int len = 0;
413
425
                int maxLen = getBufLength();
417
429
                        i++;
418
430
                }
419
431
 
420
 
                String s = new String(this.byteBuffer, this.position, len);
 
432
                String s = StringUtils.toString(this.byteBuffer, this.position, len);
421
433
                this.position += (len + 1); // update cursor
422
434
 
423
435
                return s;
434
446
                }
435
447
 
436
448
                try {
437
 
                        return new String(this.byteBuffer, this.position, len, encoding);
 
449
                        return StringUtils.toString(this.byteBuffer, this.position, len, encoding);
438
450
                } catch (UnsupportedEncodingException uEE) {
439
451
                        throw SQLError.createSQLException(Messages.getString("ByteArrayBuffer.1") //$NON-NLS-1$
440
452
                                        + encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor); //$NON-NLS-1$
443
455
                }
444
456
        }
445
457
 
446
 
        void setBufLength(int bufLengthToSet) {
 
458
        /**
 
459
         * Read a fixed length string
 
460
         */
 
461
        final String readString(String encoding, ExceptionInterceptor exceptionInterceptor, int expectedLength) throws SQLException {
 
462
                int i = this.position;
 
463
                int len = 0;
 
464
                int maxLen = getBufLength();
 
465
 
 
466
                while ((i < maxLen) && (len < expectedLength) && (this.byteBuffer[i] != 0)) {
 
467
                        len++;
 
468
                        i++;
 
469
                }
 
470
                
 
471
                if (len < expectedLength) {
 
472
                        throw SQLError.createSQLException(Messages.getString("ByteArrayBuffer.2"),
 
473
                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
 
474
                }
 
475
 
 
476
                try {
 
477
                        return StringUtils.toString(this.byteBuffer, this.position, len, encoding);
 
478
                } catch (UnsupportedEncodingException uEE) {
 
479
                        throw SQLError.createSQLException(Messages.getString("ByteArrayBuffer.1") //$NON-NLS-1$
 
480
                                        + encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor); //$NON-NLS-1$
 
481
                } finally {
 
482
                        this.position += len; // update cursor
 
483
                }
 
484
        }
 
485
 
 
486
        public void setBufLength(int bufLengthToSet) {
447
487
                this.bufLength = bufLengthToSet;
448
488
        }
449
489
 
494
534
                return this.wasMultiPacket;
495
535
        }
496
536
 
497
 
        final void writeByte(byte b) throws SQLException {
 
537
        public final void writeByte(byte b) throws SQLException {
498
538
                ensureCapacity(1);
499
539
 
500
540
                this.byteBuffer[this.position++] = b;
501
541
        }
502
542
 
503
543
        // Write a byte array
504
 
        final void writeBytesNoNull(byte[] bytes) throws SQLException {
 
544
        public final void writeBytesNoNull(byte[] bytes) throws SQLException {
505
545
                int len = bytes.length;
506
546
                ensureCapacity(len);
507
547
                System.arraycopy(bytes, 0, this.byteBuffer, this.position, len);
647
687
        final void writeStringNoNull(String s) throws SQLException {
648
688
                int len = s.length();
649
689
                ensureCapacity(len * 2);
650
 
                System.arraycopy(s.getBytes(), 0, this.byteBuffer, this.position, len);
 
690
                System.arraycopy(StringUtils.getBytes(s), 0, this.byteBuffer, this.position, len);
651
691
                this.position += len;
652
692
 
653
693
                // for (int i = 0; i < len; i++)