01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 07. April 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.converters.extended;
12:
13: import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14:
15: import java.nio.charset.Charset;
16:
17: /**
18: * Converts a java.nio.charset.Carset to a string.
19: *
20: * @author Jörg Schaible
21: * @since 1.2
22: */
23: public class CharsetConverter extends AbstractSingleValueConverter {
24:
25: public boolean canConvert(Class type) {
26: return Charset.class.isAssignableFrom(type);
27: }
28:
29: public String toString(Object obj) {
30: return obj == null ? null : ((Charset) obj).name();
31: }
32:
33: public Object fromString(String str) {
34: return Charset.forName(str);
35: }
36: }
|