@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { return Optional.of(vf.createLiteral(integerValue.byteValueExact())); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { return Optional.of(vf.createLiteral(integerValue.byteValueExact())); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { if (integerValue.compareTo(BigInteger.ZERO) >= 0) { return Optional.of(vf.createLiteral(String.valueOf(integerValue.byteValueExact()), getXsdDatatype())); } return Optional.empty(); }
@Override protected Optional<Literal> createTypedLiteral(ValueFactory vf, BigInteger integerValue) throws ArithmeticException { if (integerValue.compareTo(BigInteger.ZERO) >= 0) { return Optional.of(vf.createLiteral(String.valueOf(integerValue.byteValueExact()), getXsdDatatype())); } return Optional.empty(); }
@AtlasConversionInfo(sourceType = FieldType.DECIMAL, targetType = FieldType.BYTE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) public Byte toByte(BigDecimal value) throws AtlasConversionException { if (value == null) { return null; } try { return value.toBigInteger().byteValueExact(); } catch (ArithmeticException e) { throw new AtlasConversionException(String.format( "BigDecimal %s is greater than Byte.MAX_VALUE or less than Byte.MIN_VALUE", value)); } }
@AtlasConversionInfo(sourceType = FieldType.BIG_INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) public Byte toByte(BigInteger value) throws AtlasConversionException { if (value == null) { return null; } try { return value.byteValueExact(); } catch (ArithmeticException e) { throw new AtlasConversionException(String.format( "BigInteger %s is greater than Byte.MAX_VALUE or less than Byte.MIN_VALUE", value)); } }
return Byte.valueOf(value.byteValueExact()); if (short.class.equals(type) || Short.class.equals(type)) return Short.valueOf(value.shortValueExact());
return Byte.valueOf(bigInt.byteValueExact()); }catch ( ArithmeticException e ){
/** * Recovers the ECDSA Public key from a message hash and signature * @param messageHash a 32-character string in Latin-1 encoding representing the 32-byte message hash of the signed message * @param v The recovery id, in the range 27-34, to use to recover the correct public key * @param r The r component of the message signature, as a 32-character Latin-1 string * @param s The s component of the message signature, as a 32-character Latin-1 string * @return Output String (64 characters) in Latin-1 encoding representing the public key recovered upon success. Returns * the empty string if key recovery fails due to invalid input. * */ public static StringToken ecdsaRecover(StringToken messageHash, IntToken v, StringToken r, StringToken s, TermContext context) { byte[] hashBytes = StringUtils.getBytesIso8859_1(messageHash.stringValue()); byte vByte = v.bigIntegerValue().byteValueExact(); byte[] rBytes = StringUtils.getBytesIso8859_1(r.stringValue()); byte[] sBytes = StringUtils.getBytesIso8859_1(s.stringValue()); try { ECDSARecover key = ECDSARecover.signatureToKey(hashBytes, rBytes, sBytes, vByte); return StringToken.of(Arrays.copyOfRange(key.getPubKey(), 1, 65)); } catch (SignatureException | IllegalArgumentException e) { return StringToken.of(""); } }