01: /*
02: * Copyright (C) 2003, 2004 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 26. September 2003 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.basic;
13:
14: /**
15: * Converts a short primitive or java.lang.Short wrapper to
16: * a String.
17: *
18: * @author Joe Walnes
19: */
20: public class ShortConverter extends AbstractSingleValueConverter {
21:
22: public boolean canConvert(Class type) {
23: return type.equals(short.class) || type.equals(Short.class);
24: }
25:
26: public Object fromString(String str) {
27: int value = Integer.decode(str).intValue();
28: if (value < Short.MIN_VALUE || value > 0xFFFF) {
29: throw new NumberFormatException("For input string: \""
30: + str + '"');
31: }
32: return new Short((short) value);
33: }
34:
35: }
|