@Test public void testFromBytesBig() { LocalDateTime localDateTime = LocalDateTimeConverter.INSTANCE .fromBytes(new byte[]{8, 0, 0, 0, 85, 10, 27, 72, -9, 0, 0, 78, -108, -111, 78, -1, -1}); assertEquals(LocalDateTime.MAX, localDateTime); }
@Override public LocalDateTime fromBytes(byte[] bytes) { if (bytes.length < 2) { throw new IllegalArgumentException("Unexpected number of bytes: " + bytes.length); } int dateLength = bytes[0]; if(dateLength <= 0 || dateLength >= bytes.length - 1) { throw new CayenneCryptoException("Corrupted data for LocalDateTime: wrong encoded length"); } int timeLength = bytes.length - 1 - dateLength; byte[] date = new byte[dateLength]; byte[] time = new byte[timeLength]; System.arraycopy(bytes, 1, date, 0, dateLength); System.arraycopy(bytes, dateLength + 1, time, 0, timeLength); LocalDate localDate = LocalDate.ofEpochDay(longConverter.fromBytes(date)); LocalTime localTime = LocalTime.ofNanoOfDay(longConverter.fromBytes(time)); return LocalDateTime.of(localDate, localTime); }
LocalDateTimeConverter implements BytesConverter<LocalDateTime> { @Override public LocalDateTime fromBytes(byte[] bytes) { if (bytes.length < 2) { throw new IllegalArgumentException("Unexpected number of bytes: " + bytes.length); } int dateLength = bytes[0]; if(dateLength <= 0 || dateLength >= bytes.length - 1) { throw new CayenneCryptoException("Corrupted data for LocalDateTime: wrong encoded length"); } int timeLength = bytes.length - 1 - dateLength; byte[] date = new byte[dateLength]; byte[] time = new byte[timeLength]; System.arraycopy(bytes, 1, date, 0, dateLength); System.arraycopy(bytes, dateLength + 1, time, 0, timeLength); LocalDate localDate = LocalDate.ofEpochDay(longConverter.fromBytes(date)); LocalTime localTime = LocalTime.ofNanoOfDay(longConverter.fromBytes(time)); return LocalDateTime.of(localDate, localTime); } }
LocalDateTimeConverter implements BytesConverter<LocalDateTime> { @Override public LocalDateTime fromBytes(byte[] bytes) { if (bytes.length < 2) { throw new IllegalArgumentException("Unexpected number of bytes: " + bytes.length); } int dateLength = bytes[0]; if(dateLength <= 0 || dateLength >= bytes.length - 1) { throw new CayenneCryptoException("Corrupted data for LocalDateTime: wrong encoded length"); } int timeLength = bytes.length - 1 - dateLength; byte[] date = new byte[dateLength]; byte[] time = new byte[timeLength]; System.arraycopy(bytes, 1, date, 0, dateLength); System.arraycopy(bytes, dateLength + 1, time, 0, timeLength); LocalDate localDate = LocalDate.ofEpochDay(longConverter.fromBytes(date)); LocalTime localTime = LocalTime.ofNanoOfDay(longConverter.fromBytes(time)); return LocalDateTime.of(localDate, localTime); } LocalDateTimeConverter(BytesConverter<Long> longConverter); }
LocalDateTimeConverter implements BytesConverter<LocalDateTime> { @Override public LocalDateTime fromBytes(byte[] bytes) { if (bytes.length < 2) { throw new IllegalArgumentException("Unexpected number of bytes: " + bytes.length); } int dateLength = bytes[0]; if(dateLength <= 0 || dateLength >= bytes.length - 1) { throw new CayenneCryptoException("Corrupted data for LocalDateTime: wrong encoded length"); } int timeLength = bytes.length - 1 - dateLength; byte[] date = new byte[dateLength]; byte[] time = new byte[timeLength]; System.arraycopy(bytes, 1, date, 0, dateLength); System.arraycopy(bytes, dateLength + 1, time, 0, timeLength); LocalDate localDate = LocalDate.ofEpochDay(longConverter.fromBytes(date)); LocalTime localTime = LocalTime.ofNanoOfDay(longConverter.fromBytes(time)); return LocalDateTime.of(localDate, localTime); } LocalDateTimeConverter(BytesConverter<Long> longConverter); @Override LocalDateTime fromBytes(byte[] bytes); @Override byte[] toBytes(LocalDateTime value); }
LocalDateTimeConverter implements BytesConverter<LocalDateTime> { @Override public LocalDateTime fromBytes(byte[] bytes) { if (bytes.length < 2) { throw new IllegalArgumentException("Unexpected number of bytes: " + bytes.length); } int dateLength = bytes[0]; if(dateLength <= 0 || dateLength >= bytes.length - 1) { throw new CayenneCryptoException("Corrupted data for LocalDateTime: wrong encoded length"); } int timeLength = bytes.length - 1 - dateLength; byte[] date = new byte[dateLength]; byte[] time = new byte[timeLength]; System.arraycopy(bytes, 1, date, 0, dateLength); System.arraycopy(bytes, dateLength + 1, time, 0, timeLength); LocalDate localDate = LocalDate.ofEpochDay(longConverter.fromBytes(date)); LocalTime localTime = LocalTime.ofNanoOfDay(longConverter.fromBytes(time)); return LocalDateTime.of(localDate, localTime); } LocalDateTimeConverter(BytesConverter<Long> longConverter); @Override LocalDateTime fromBytes(byte[] bytes); @Override byte[] toBytes(LocalDateTime value); static final BytesConverter<LocalDateTime> INSTANCE; }