001package gu.dtalk;
002
003import com.google.common.base.Throwables;
004
005import net.gdface.utils.FaceUtilits;
006
007/**
008 * base64格式二进制数据选项
009 * @author guyadong
010 *
011 */
012public class Base64Option extends BaseBinary {
013
014        public Base64Option() {
015        }
016
017        @Override
018        public OptionType getType() {
019                return OptionType.BASE64;
020        }
021        @Override
022        public Base64Option asValue(String input) {
023                try {
024                        setValue(FaceUtilits.getBytes(input));
025                        return this;
026                } catch (Exception e) {
027                        Throwables.throwIfUnchecked(e);
028                        throw new RuntimeException(e);
029                }
030        }
031        /**
032         * 从input中读取字节流转为byte[]调用{@link #setValue(Object)}
033         * @param <T> 参见 {@link FaceUtilits#getBytes(Object)}
034         */
035        public <T>Base64Option asValue(T input) {
036                try {
037                        setValue(FaceUtilits.getBytes(input));
038                        return this;
039                } catch (Exception e) {
040                        Throwables.throwIfUnchecked(e);
041                        throw new RuntimeException(e);
042                }
043        }
044        @Override
045        public Base64Option asDefaultValue(String input) {
046                try {
047                        setDefaultValue(FaceUtilits.getBytes(input));
048                        return this;
049                } catch (Exception e) {
050                        Throwables.throwIfUnchecked(e);
051                        throw new RuntimeException(e);
052                }
053        }
054        /**
055         * 从input中读取字节流转为byte[]调用{@link #setDefaultValue(Object)}
056         * @param <T> 参见 {@link FaceUtilits#getBytes(Object)}
057         */
058        public <T>Base64Option asDefaultValue(T input) {
059                try {
060                        setDefaultValue(FaceUtilits.getBytes(input));
061                        return this;
062                } catch (Exception e) {
063                        Throwables.throwIfUnchecked(e);
064                        throw new RuntimeException(e);
065                }
066        }
067}