Esempio n. 1
0
 private void readUtf8_slow(int charCount, int charIndex) {
   char[] chars = this.chars;
   byte[] buffer = this.buffer;
   while (charIndex < charCount) {
     if (position == limit) require(1);
     int b = buffer[position++] & 0xFF;
     switch (b >> 4) {
       case 0:
       case 1:
       case 2:
       case 3:
       case 4:
       case 5:
       case 6:
       case 7:
         chars[charIndex] = (char) b;
         break;
       case 12:
       case 13:
         if (position == limit) require(1);
         chars[charIndex] = (char) ((b & 0x1F) << 6 | buffer[position++] & 0x3F);
         break;
       case 14:
         require(2);
         chars[charIndex] =
             (char)
                 ((b & 0x0F) << 12 | (buffer[position++] & 0x3F) << 6 | buffer[position++] & 0x3F);
         break;
     }
     charIndex++;
   }
 }
Esempio n. 2
0
 private int readInt_slow(boolean optimizePositive) {
   // The buffer is guaranteed to have at least 1 byte.
   int b = buffer[position++];
   int result = b & 0x7F;
   if ((b & 0x80) != 0) {
     require(1);
     byte[] buffer = this.buffer;
     b = buffer[position++];
     result |= (b & 0x7F) << 7;
     if ((b & 0x80) != 0) {
       require(1);
       b = buffer[position++];
       result |= (b & 0x7F) << 14;
       if ((b & 0x80) != 0) {
         require(1);
         b = buffer[position++];
         result |= (b & 0x7F) << 21;
         if ((b & 0x80) != 0) {
           require(1);
           b = buffer[position++];
           result |= (b & 0x7F) << 28;
         }
       }
     }
   }
   return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
 }
Esempio n. 3
0
 private int readUtf8Length_slow(int b) {
   int result = b & 0x3F; // Mask all but first 6 bits.
   if ((b & 0x40) != 0) { // Bit 7 means another byte, bit 8 means UTF8.
     require(1);
     byte[] buffer = this.buffer;
     b = buffer[position++];
     result |= (b & 0x7F) << 6;
     if ((b & 0x80) != 0) {
       require(1);
       b = buffer[position++];
       result |= (b & 0x7F) << 13;
       if ((b & 0x80) != 0) {
         require(1);
         b = buffer[position++];
         result |= (b & 0x7F) << 20;
         if ((b & 0x80) != 0) {
           require(1);
           b = buffer[position++];
           result |= (b & 0x7F) << 27;
         }
       }
     }
   }
   return result;
 }
Esempio n. 4
0
 private String readAscii_slow() {
   position--; // Re-read the first byte.
   // Copy chars currently in buffer.
   int charCount = limit - position;
   if (charCount > chars.length) chars = new char[charCount * 2];
   char[] chars = this.chars;
   byte[] buffer = this.buffer;
   for (int i = position, ii = 0, n = limit; i < n; i++, ii++) chars[ii] = (char) buffer[i];
   position = limit;
   // Copy additional chars one by one.
   while (true) {
     require(1);
     int b = buffer[position++];
     if (charCount == chars.length) {
       char[] newChars = new char[charCount * 2];
       System.arraycopy(chars, 0, newChars, 0, charCount);
       chars = newChars;
       this.chars = newChars;
     }
     if ((b & 0x80) == 0x80) {
       chars[charCount++] = (char) (b & 0x7F);
       break;
     }
     chars[charCount++] = (char) b;
   }
   return new String(chars, 0, charCount);
 }
Esempio n. 5
0
 /** Reads a 4 byte int. */
 public int readInt() throws KryoException {
   require(4);
   byte[] buffer = this.buffer;
   int position = this.position;
   this.position = position + 4;
   return (buffer[position] & 0xFF) << 24 //
       | (buffer[position + 1] & 0xFF) << 16 //
       | (buffer[position + 2] & 0xFF) << 8 //
       | buffer[position + 3] & 0xFF;
 }
Esempio n. 6
0
 /** Discards the specified number of bytes. */
 public void skip(int count) throws KryoException {
   int skipCount = Math.min(limit - position, count);
   while (true) {
     position += skipCount;
     count -= skipCount;
     if (count == 0) break;
     skipCount = Math.min(count, capacity);
     require(skipCount);
   }
 }
Esempio n. 7
0
 /** Reads an 8 byte long. */
 public long readLong() throws KryoException {
   require(8);
   byte[] buffer = this.buffer;
   return (long) buffer[position++] << 56 //
       | (long) (buffer[position++] & 0xFF) << 48 //
       | (long) (buffer[position++] & 0xFF) << 40 //
       | (long) (buffer[position++] & 0xFF) << 32 //
       | (long) (buffer[position++] & 0xFF) << 24 //
       | (buffer[position++] & 0xFF) << 16 //
       | (buffer[position++] & 0xFF) << 8 //
       | buffer[position++] & 0xFF;
 }
Esempio n. 8
0
 /** Reads count bytes and writes them to the specified byte[], starting at offset. */
 public void readBytes(byte[] bytes, int offset, int count) throws KryoException {
   if (bytes == null) throw new IllegalArgumentException("bytes cannot be null.");
   int copyCount = Math.min(limit - position, count);
   while (true) {
     System.arraycopy(buffer, position, bytes, offset, copyCount);
     position += copyCount;
     count -= copyCount;
     if (count == 0) break;
     offset += copyCount;
     copyCount = Math.min(count, capacity);
     require(copyCount);
   }
 }
Esempio n. 9
0
 private long readLong_slow(boolean optimizePositive) {
   // The buffer is guaranteed to have at least 1 byte.
   int b = buffer[position++];
   long result = b & 0x7F;
   if ((b & 0x80) != 0) {
     require(1);
     byte[] buffer = this.buffer;
     b = buffer[position++];
     result |= (b & 0x7F) << 7;
     if ((b & 0x80) != 0) {
       require(1);
       b = buffer[position++];
       result |= (b & 0x7F) << 14;
       if ((b & 0x80) != 0) {
         require(1);
         b = buffer[position++];
         result |= (b & 0x7F) << 21;
         if ((b & 0x80) != 0) {
           require(1);
           b = buffer[position++];
           result |= (long) (b & 0x7F) << 28;
           if ((b & 0x80) != 0) {
             require(1);
             b = buffer[position++];
             result |= (long) (b & 0x7F) << 35;
             if ((b & 0x80) != 0) {
               require(1);
               b = buffer[position++];
               result |= (long) (b & 0x7F) << 42;
               if ((b & 0x80) != 0) {
                 require(1);
                 b = buffer[position++];
                 result |= (long) (b & 0x7F) << 49;
                 if ((b & 0x80) != 0) {
                   require(1);
                   b = buffer[position++];
                   result |= (long) b << 56;
                 }
               }
             }
           }
         }
       }
     }
   }
   if (!optimizePositive) result = (result >>> 1) ^ -(result & 1);
   return result;
 }
Esempio n. 10
0
 /** Reads a 2 byte char. */
 public char readChar() throws KryoException {
   require(2);
   return (char) (((buffer[position++] & 0xFF) << 8) | (buffer[position++] & 0xFF));
 }
Esempio n. 11
0
 /** Reads a 1 byte boolean. */
 public boolean readBoolean() throws KryoException {
   require(1);
   return buffer[position++] == 1;
 }
Esempio n. 12
0
 /** Reads a 2 byte short as an int from 0 to 65535. */
 public int readShortUnsigned() throws KryoException {
   require(2);
   return ((buffer[position++] & 0xFF) << 8) | (buffer[position++] & 0xFF);
 }
Esempio n. 13
0
 /** Reads a 2 byte short. */
 public short readShort() throws KryoException {
   require(2);
   return (short) (((buffer[position++] & 0xFF) << 8) | (buffer[position++] & 0xFF));
 }
Esempio n. 14
0
 /** Reads a byte as an int from 0 to 255. */
 public int readByteUnsigned() throws KryoException {
   require(1);
   return buffer[position++] & 0xFF;
 }
Esempio n. 15
0
 /** Reads a single byte. */
 public byte readByte() throws KryoException {
   require(1);
   return buffer[position++];
 }