/*
Reads unsigned short in Intel byte order.
973643
protected int readUShort(InputStream in) throws IOException { // IA VISIBILITY CHANGE FOR SUBCLASS USE
        int b = readUByte(in);
        return ((int)readUByte(in) << 8) | b;
    }
444730
@Override
	public void writeShort(short v) throws IOException {
		outputStream.write(0xFF & v);
		outputStream.write(0xFF & (v >> 8));
		bytesWritten += 2;
	}
510469
public static short readShortLittleEndian(InputStream io) throws IOException {
		int value = io.read();
		if (value < 0) throw new EOFException();
		int i = io.read();
		if (i < 0) throw new EOFException();
		return (short)(value | (i << 8));
	}
1332664
public static short byteArrayToShortLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getShort();
    }
426726
public int readShortBE() throws IOException {
        int h = read();
        int l = read();
        if (-1 == h || -1 == l)
            return -1;
        return DataUtils.toShort(h, l);
    }
1156378
static byte[] shortToBytes(short value) {
        byte[] bytes = new byte[2];
        if (PlatformDependent.BIG_ENDIAN_NATIVE_ORDER) {
            bytes[1] = (byte) ((value >> 8) & 0xff);
            bytes[0] = (byte) (value & 0xff);
        } else {
            bytes[0] = (byte) ((value >> 8) & 0xff);
            bytes[1] = (byte) (value & 0xff);
        }
        return bytes;
    }
1218606
private static byte readByte(boolean[] rawbits, int startIndex) {
    int n = rawbits.length - startIndex;
    if (n >= 8) {
      return (byte) readCode(rawbits, startIndex, 8);
    }
    return (byte) (readCode(rawbits, startIndex, n) << (8 - n));
  }
1061224
public static int readUnsignedVarint(ByteBuffer buffer) throws IOException {
    int val = 0;
    int bits = 0;
    while(true) {
      final int data = buffer.get();
      val |= (data & 0x7F) << bits;
      if((data & 0x80) == 0) {
        return val;
      }
      bits += 7;
      if(bits > 35) {
        throw new IOException("Variable length quantity is too long for expected integer.");
      }
    }
  }
1271270
public static short readShortLittleEndian(IO.ReadableByteStream io) throws IOException {
		int value = io.read();
		if (value < 0) throw new EOFException();
		int i = io.read();
		if (i < 0) throw new EOFException();
		return (short)(value | (i << 8));
	}
808870
public static final short readShort(byte[] array, int offset)
    {
        if (array.length < offset + 2)
        {
            throw new IllegalArgumentException("no room in array");
        }
        return 
                (short) (((array[offset]<<8) & 0xff00) +
                (array[offset + 1] & 0xff ));
    }
856552
public static short bytesToShort(byte[] bytes, int offset) {
        short result = 0x0000;
        int end = offset + 2;
        for (int i = 0; i < 2; i++) {
            result |= (bytes[end - i - 1] & 0xff) << (8 * i);
        }
        return result;
    }
751910
public short[] readShorts (int length) throws KryoException {
		short[] array = new short[length];
		if (optional(length << 1) == length << 1) {
			byte[] buffer = this.buffer;
			int p = this.position;
			for (int i = 0; i < length; i++, p += 2)
				array[i] = (short)((buffer[p] & 0xFF) | ((buffer[p + 1] & 0xFF)) << 8);
			position = p;
		} else {
			for (int i = 0; i < length; i++)
				array[i] = readShort();
		}
		return array;
	}
292213
def read_uint(self):
		
		if self.reader.sysinfo.ProcessorArchitecture == PROCESSOR_ARCHITECTURE.AMD64:
			return int.from_bytes(self.read(8), byteorder = 'little', signed = False)
		else:
			return int.from_bytes(self.read(4), byteorder = 'little', signed = False)
1034044
public static short readShort(ArrayView source, int position) {
        return (short) ((source.get(position) & 0xFF) << 8
                | (source.get(position + 1) & 0xFF));
    }
130120
private static short readLEShort(InputStream in) throws IOException {
		short s = (byte)in.read();
		s |= (byte)in.read() << 8;
		return s;
	}
42577
public static int readUnsignedMediumInt(IoBuffer in) {
        byte[] bytes = new byte[3];
        in.get(bytes);
        int val = 0;
        val += (bytes[0] & 0xFF) * 256 * 256;
        val += (bytes[1] & 0xFF) * 256;
        val += (bytes[2] & 0xFF);
        return val;
    }
913607
def read_uint8(self, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack('%sB' % endian)