/** * Parses the byte array argument as if it was a double value and returns the * result. Throws NumberFormatException if the byte buffer does not represent a * double value. * * @return double, the value represented by the argument * @throws NumberFormatException if the argument could not be parsed as a double */ public static double parseDouble(ByteBuf bytes) { return parseDouble(bytes, bytes.readerIndex(), bytes.readableBytes()); }
/** * Parses the byte buffer argument as if it was an int value and returns the * result. Throws NumberFormatException if the byte array does not represent an * int quantity. * * @return int the value represented by the argument * @throws NumberFormatException if the argument could not be parsed as an int quantity. */ public static int parseInt(ByteBuf bytes, int start, int length) { return parseInt(bytes, start, length, 10); }
/** * Parses the byte buffer argument as if it was a long value and returns the * result. Throws NumberFormatException if the string does not represent a * long quantity. * * @param bytes the string byte buffer * @param start * @param length a UTF-8 encoded string representation of a long quantity. * @return long the value represented by the argument * @throws NumberFormatException if the argument could not be parsed as a long quantity. */ public static long parseLong(ByteBuf bytes, int start, int length) { return parseLong(bytes, start, length, 10); }
case INT1: case INT2: datum = DatumFactory.createInt2((short) NumberUtil.parseInt(buf)); break; case INT4: datum = DatumFactory.createInt4(NumberUtil.parseInt(buf)); break; case INT8: datum = DatumFactory.createInt8(NumberUtil.parseLong(buf)); break; case FLOAT4: break; case FLOAT8: datum = DatumFactory.createFloat8(NumberUtil.parseDouble(buf)); break; case TEXT: {
case INT2: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt2((short)NumberUtil.parseInt(bytes, 0, bytes.length)); break; case INT4: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt4(NumberUtil.parseInt(bytes, 0, bytes.length)); break; case INT8: case FLOAT8: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat8(NumberUtil.parseDouble(bytes, 0, bytes.length)); break; case TEXT:
return parseInt(bytes.array(), start, length); return parseIntInternal(bytes, memoryAddress, start, length, offset, radix, negative);
return parseInt(bytes.array(), start, length); return parseLongInternal(bytes, memoryAddress, start, length, offset, radix, negative);
return parseDouble(bytes.array(), start, length); int decicalOffset = -1; /* Number of mantissa digits BEFORE decimal point. */ for (; offset < end; offset++) { if (!isDigit(PlatformDependent.getByte(memoryAddress + offset))) { if ((PlatformDependent.getByte(memoryAddress + offset) != '.') || (decicalOffset >= 0)) { break; if (isDigit(PlatformDependent.getByte(memoryAddress + offset))) { exponent = exponent * 10 + (PlatformDependent.getByte(memoryAddress + offset) - '0'); } else {
/** * Converts a byte array to a short value * @param bytes byte array * @param offset offset into array * @param length length, has to be {@link #SIZEOF_SHORT} * @return the short value * @throws IllegalArgumentException if length is not {@link #SIZEOF_SHORT} * or if there's not enough room in the array at the offset indicated. */ public static short toShort(byte[] bytes, int offset, final int length) { if (length != SIZEOF_SHORT || offset + length > bytes.length) { throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_SHORT); } short n = 0; n ^= bytes[offset] & 0xFF; n <<= 8; n ^= bytes[offset+1] & 0xFF; return n; }
case INT1: case INT2: datum = DatumFactory.createInt2((short) NumberUtil.parseInt(buf)); break; case INT4: datum = DatumFactory.createInt4(NumberUtil.parseInt(buf)); break; case INT8: datum = DatumFactory.createInt8(NumberUtil.parseLong(buf)); break; case FLOAT4: break; case FLOAT8: datum = DatumFactory.createFloat8(NumberUtil.parseDouble(buf)); break; case TEXT: {
case INT2: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt2((short)NumberUtil.parseInt(bytes, 0, bytes.length)); break; case INT4: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt4(NumberUtil.parseInt(bytes, 0, bytes.length)); break; case INT8: case FLOAT8: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat8(NumberUtil.parseDouble(bytes, 0, bytes.length)); break; case TEXT:
return parseInt(bytes.array(), start, length); return parseIntInternal(bytes, memoryAddress, start, length, offset, radix, negative);
return parseInt(bytes.array(), start, length); return parseLongInternal(bytes, memoryAddress, start, length, offset, radix, negative);
return parseDouble(bytes.array(), start, length); int decicalOffset = -1; /* Number of mantissa digits BEFORE decimal point. */ for (; offset < end; offset++) { if (!isDigit(PlatformDependent.getByte(memoryAddress + offset))) { if ((PlatformDependent.getByte(memoryAddress + offset) != '.') || (decicalOffset >= 0)) { break; if (isDigit(PlatformDependent.getByte(memoryAddress + offset))) { exponent = exponent * 10 + (PlatformDependent.getByte(memoryAddress + offset) - '0'); } else {
/** * Converts a byte array to a short value * @param bytes byte array * @param offset offset into array * @param length length, has to be {@link #SIZEOF_SHORT} * @return the short value * @throws IllegalArgumentException if length is not {@link #SIZEOF_SHORT} * or if there's not enough room in the array at the offset indicated. */ public static short toShort(byte[] bytes, int offset, final int length) { if (length != SIZEOF_SHORT || offset + length > bytes.length) { throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_SHORT); } short n = 0; n ^= bytes[offset] & 0xFF; n <<= 8; n ^= bytes[offset+1] & 0xFF; return n; }
case INT1: case INT2: datum = DatumFactory.createInt2((short) NumberUtil.parseInt(buf)); break; case INT4: datum = DatumFactory.createInt4(NumberUtil.parseInt(buf)); break; case INT8: datum = DatumFactory.createInt8(NumberUtil.parseLong(buf)); break; case FLOAT4: break; case FLOAT8: datum = DatumFactory.createFloat8(NumberUtil.parseDouble(buf)); break; case TEXT: {