Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (c) 2006-2011 Christian Plattner.
      3  * All rights reserved.
      4  * Please refer to the LICENSE.txt for licensing details.
      5  */
      6 package ch.ethz.ssh2.util;
      7 
      8 import java.io.UnsupportedEncodingException;
      9 
     10 /**
     11  * @author Christian Plattner
     12  * @version $Id: StringEncoder.java 43 2011-06-21 18:34:06Z dkocher (at) sudo.ch $
     13  */
     14 public class StringEncoder
     15 {
     16 	public static byte[] GetBytes(String data)
     17 	{
     18         try {
     19             return data.getBytes("UTF-8");
     20         }
     21         catch(UnsupportedEncodingException e) {
     22             throw new RuntimeException(e);
     23         }
     24     }
     25 
     26 	public static String GetString(byte[] data)
     27 	{
     28 		return GetString(data, 0, data.length);
     29 	}
     30 
     31 	public static String GetString(byte[] data, int off, int len)
     32 	{
     33         try {
     34             return new String(data, off, len, "UTF-8");
     35         }
     36         catch(UnsupportedEncodingException e) {
     37             throw new RuntimeException(e);
     38         }
     39     }
     40 }
     41