@Override public Float parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Float.parseFloat(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 32-bits float value from \"%s\"", value)); } }
@Override public Integer parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Integer.parseInt(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 32-bits int value from \"%s\"", value)); } }
@Override public BigInteger parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : new BigInteger(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse varint value from \"%s\"", value), e); } }
@Override public UUID parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : UUID.fromString(value); } catch (IllegalArgumentException e) { throw new InvalidTypeException( String.format("Cannot parse UUID value from \"%s\"", value), e); } }
@Override public Long parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 64-bits long value from \"%s\"", value)); } }
@Override public Byte parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Byte.parseByte(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 8-bits int value from \"%s\"", value)); } }
@Override public Short parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Short.parseShort(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 16-bits int value from \"%s\"", value)); } }
@Override public float deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return 0; if (bytes.remaining() != 4) throw new InvalidTypeException( "Invalid 32-bits float value, expecting 4 bytes but got " + bytes.remaining()); return bytes.getFloat(bytes.position()); } }
@Override public Double parse(String value) { try { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : Double.parseDouble(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse 64-bits double value from \"%s\"", value)); } }
@Override public short deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return 0; if (bytes.remaining() != 2) throw new InvalidTypeException( "Invalid 16-bits integer value, expecting 2 bytes but got " + bytes.remaining()); return bytes.getShort(bytes.position()); } }
@Override public long deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return 0; if (bytes.remaining() != 8) throw new InvalidTypeException( "Invalid 64-bits long value, expecting 8 bytes but got " + bytes.remaining()); return bytes.getLong(bytes.position()); } }
@Override public boolean deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return false; if (bytes.remaining() != 1) throw new InvalidTypeException( "Invalid boolean value, expecting 1 byte but got " + bytes.remaining()); return bytes.get(bytes.position()) != 0; } }
@Override public double deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return 0; if (bytes.remaining() != 8) throw new InvalidTypeException( "Invalid 64-bits double value, expecting 8 bytes but got " + bytes.remaining()); return bytes.getDouble(bytes.position()); } }
@Override public Boolean parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; if (value.equalsIgnoreCase(Boolean.FALSE.toString())) return false; if (value.equalsIgnoreCase(Boolean.TRUE.toString())) return true; throw new InvalidTypeException( String.format("Cannot parse boolean value from \"%s\"", value)); }
@Override public ByteBuffer serialize(String value, ProtocolVersion protocolVersion) { if (value != null && !ASCII_PATTERN.matcher(value).matches()) { throw new InvalidTypeException(String.format("%s is not a valid ASCII String", value)); } return super.serialize(value, protocolVersion); }
@Override public InetAddress deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null || bytes.remaining() == 0) return null; try { return InetAddress.getByAddress(Bytes.getArray(bytes)); } catch (UnknownHostException e) { throw new InvalidTypeException( "Invalid bytes for inet value, got " + bytes.remaining() + " bytes"); } } }
@Override public InvalidTypeException copy() { return new InvalidTypeException(getMessage(), this); } }
@Override public String parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("text or varchar values must be enclosed by single quotes"); return ParseUtils.unquote(value); }
@Override public String format(UUID value) { if (value == null) return "NULL"; if (value.version() != 1) throw new InvalidTypeException( String.format("%s is not a Type 1 (time-based) UUID", value)); return super.format(value); }
@Override public ByteBuffer serialize(UUID value, ProtocolVersion protocolVersion) { if (value == null) return null; if (value.version() != 1) throw new InvalidTypeException( String.format("%s is not a Type 1 (time-based) UUID", value)); return super.serialize(value, protocolVersion); } }