com.zakgof.tools.io.SimpleLocalDateSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tools Show documentation
Show all versions of tools Show documentation
Utility classes used internally by various zakgof projects.
package com.zakgof.tools.io;
import java.io.IOException;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
public class SimpleLocalDateSerializer implements ISimpleSerializer {
public static SimpleLocalDateSerializer INSTANCE = new SimpleLocalDateSerializer();
private SimpleLocalDateSerializer() {
}
@Override
public void write(SimpleOutputStream out, LocalDate val) throws IOException {
long epochDay = val.getLong(ChronoField.EPOCH_DAY);
out.write(epochDay);
}
@Override
public LocalDate read(SimpleInputStream in) throws IOException {
Long epochDay = in.readLong();
if (epochDay == null)
return null;
return LocalDate.ofEpochDay(epochDay);
}
}