1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
3  * Copyright (C) 2006, 2007, 2018 XStream Committers.
4  * All rights reserved.
5  *
6  * The software in this package is published under the terms of the BSD
7  * style license a copy of which has been included with this distribution in
8  * the LICENSE.txt file.
9  * 
10  * Created on 26. September 2003 by Joe Walnes
11  */

12 package com.thoughtworks.xstream.converters.basic;
13
14 /**
15  * Converts a byte primitive or java.lang.Byte wrapper to
16  * a String.
17  *
18  * @author Joe Walnes
19  */

20 public class ByteConverter extends AbstractSingleValueConverter {
21
22     public boolean canConvert(Class type) {
23         return type == byte.class || type == Byte.class;
24     }
25
26     public Object fromString(String str) {
27         int value = Integer.decode(str).intValue();
28         if(value < Byte.MIN_VALUE || value > 0xFF) {
29             throw new NumberFormatException("For input string: \"" + str + '"');
30         }
31         return new Byte((byte)value);
32     }
33
34 }
35