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 ByteArrayConverter.
17   */
18  public class ByteArrayConverter extends AbstractConverter<byte[]> {
19  
20      /**
21       * Instantiates a new byte array converter.
22       */
23      public ByteArrayConverter() {
24          super(byte[].class);
25      }
26  
27      @Override
28      public byte[] fromString(String text) throws Exception {
29          return text != null ? text.getBytes(Charset.defaultCharset()) : null;
30      }
31  
32      @Override
33      public String toString(byte[] value) throws Exception {
34          return value != null ? new String(value, Charset.defaultCharset()) : "";
35      }
36  }