Get a property which is a number of bytes expressed either as an integer (number of bytes) or an integer followed by K
(number of kilobytes) or an integer followed by M (for megabytes). Examples: 1048, 64k, 10M
329326
public static int getOptionalDataSizeProperty(ServiceProperties properties, String propertyName, int defaultValue) {
        String value = getOptionalProperty(properties, propertyName, Integer.toString(defaultValue));
        return Utils.parseDataSize(value);
    }
508863
public static int bytesToInt(byte[] bytes, int offset) {
        // 
        int result = 0x00000000;

        int length;
        if (bytes.length - offset < 4) // maximum byte size for int data type
                                        // is 4
            length = bytes.length - offset;
        else
            length = 4;

        int end = offset + length;
        for (int i = 0; i < length; i++) {
            result |= (bytes[end - i - 1] & 0xff) << (8 * i); // TODO uudashr: CHECK FOR IMPROVEMENT
        }
        return result;
    }
1228030
public byte getByte(final String key) {
		final String value = getProperty(key);
		if (value == null) {
			throw new NumberFormatException("Couldn't parse property to byte.");
		}
		return Byte.parseByte(value);
	}
298522
def bytes(self):
        """"""
        flagByte = 0x00
        messageType = 0
        if self._messageType is not None:
            messageType = self._messageType << 5
        extendedBit = 0 if self._extended is None else self._extended << 4
        hopsMax = 0 if self._hopsMax is None else self._hopsMax
        hopsLeft = 0 if self._hopsLeft is None else (self._hopsLeft << 2)
        flagByte = flagByte | messageType | extendedBit | hopsLeft | hopsMax
        return bytes([flagByte])
505187
function intToBytes(num) {
	var bytes = [];

	for(var i=7 ; i>=0 ; --i) {
		bytes[i] = num & (255);
		num = num >> 8;
	}

	return bytes;
}
326730
def num2bytes(value, size):
    """"""
    res = []
    for _ in range(size):
        res.append(value & 0xFF)
        value = value >> 8
    assert value == 0
    return bytes(bytearray(list(reversed(res))))
1007145
public byte getByte(Integer type)
   {
      byte result = 0;

      byte[] item = m_map.get(type);
      if (item != null)
      {
         result = item[0];
      }

      return (result);
   }
784095
private String format(final long bytes) {
        if (bytes > MB) {
            return String.valueOf(bytes / MB) + " MB";
        }
        return String.valueOf(bytes / KB) + " KB";
    }
525235
def to_unit_memory(number):
    """"""
    kb = 1024

    number /= kb

    if number < 100:
        return '{} Kb'.format(round(number, 2))

    number /= kb
    if number < 300:
        return '{} Mb'.format(round(number, 2))

    number /= kb

    return '{} Gb'.format(round(number, 2))
257156
def get_numeric_type_property(value, is_bytes=False):
    """"""

    obj = unidata.ascii_numeric_type if is_bytes else unidata.unicode_numeric_type

    if value.startswith('^'):
        negated = value[1:]
        value = '^' + unidata.unicode_alias['numerictype'].get(negated, negated)
    else:
        value = unidata.unicode_alias['numerictype'].get(value, value)

    return obj[value]
1350081
def bytes_needed(self):
            ''''''
            if self.native:
                ret = self.native.expected_length - self.buf_len()
            else:
                ret = self.expected_length - self.buf_len()
            
            if ret <= 0:
                return 1
            return ret
386939
static String Megabytes(ByteAmount amount) {
    return String.format("%sMi", Long.toString(amount.asMegabytes()));
  }
1205614
def get_len(self, key):
        """"""
        data = self.model.get_data()
        return len(data[key])
900269
def int_to_bytes(i, minlen=1, order='big'):  # pragma: no cover
        """"""
        blen = max(minlen, PGPObject.int_byte_len(i), 1)

        if six.PY2:
            r = iter(_ * 8 for _ in (range(blen) if order == 'little' else range(blen - 1, -1, -1)))
            return bytes(bytearray((i >> c) & 0xff for c in r))

        return i.to_bytes(blen, order)
1036315
def int_to_bytes(int_, width = None):
	
	if(width == None):
		width = int_.bit_length()
	byts = math.ceil(width / 8)
	return bytes([ (int_ >> (shift * 8)) & 0xff for shift in range(byts)])
885215
def matchBytes(self, bytes):
        """"""
        p = self.position
        data = self[p:p + len(bytes)]
        rv = data.startswith(bytes)
        if rv:
            self.position += len(bytes)
        return rv
1242840
public Integer getIntegerProperty(String property, boolean required) {
		Integer integerValue = null;
		String value = getProperty(property, required);
		if (value != null) {
			try {
				integerValue = Integer.valueOf(value);
			} catch (NumberFormatException e) {
				throw new GeoPackageException(GEOPACKAGE_PROPERTIES_FILE
						+ " property file property '" + property
						+ "' must be an integer");
			}
		}
		return integerValue;
	}