View Javadoc
1   package org.bremersee.ldaptive.transcoder;
2   
3   import java.time.OffsetDateTime;
4   import java.time.ZonedDateTime;
5   import java.util.Optional;
6   import org.ldaptive.ad.transcode.FileTimeValueTranscoder;
7   import org.ldaptive.transcode.AbstractStringValueTranscoder;
8   
9   /**
10   * The file time value transcoder.
11   *
12   * @author Christian Bremer
13   */
14  public class FileTimeToOffsetDateTimeValueTranscoder extends
15      AbstractStringValueTranscoder<OffsetDateTime> {
16  
17    private static final FileTimeValueTranscoder transcoder = new FileTimeValueTranscoder();
18  
19    /**
20     * Instantiates a new file time to offset date time value transcoder.
21     */
22    public FileTimeToOffsetDateTimeValueTranscoder() {
23      super();
24    }
25  
26    @Override
27    public OffsetDateTime decodeStringValue(String value) {
28      return Optional.ofNullable(value)
29          .filter(v -> !v.isBlank() && !v.equals("0"))
30          .map(transcoder::decodeStringValue)
31          .map(ZonedDateTime::toOffsetDateTime)
32          .orElse(null);
33    }
34  
35    @Override
36    public String encodeStringValue(OffsetDateTime value) {
37      return Optional.ofNullable(value)
38          .map(OffsetDateTime::toZonedDateTime)
39          .map(transcoder::encodeStringValue)
40          .orElse(null);
41    }
42  
43    @Override
44    public Class<OffsetDateTime> getType() {
45      return OffsetDateTime.class;
46    }
47  }