View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.bean.conversion;
12  
13  import java.nio.charset.Charset;
14  
15  /**
16   * The Class CharsetConverter.
17   */
18  public class CharsetConverter extends AbstractConverter<Charset> {
19  
20      /**
21       * Instantiates a new charset converter.
22       */
23      public CharsetConverter() {
24          super(Charset.class);
25      }
26  
27      @Override
28      public Charset fromString(String text) throws Exception {
29          if (text != null && !text.isEmpty()) {
30              return Charset.forName(text);
31          }
32          return null;
33      }
34  
35      @Override
36      public String toString(Charset value) throws Exception {
37          return value != null ? value.name() : "";
38      }
39  
40  }