All Downloads are FREE. Search and download functionalities are using the official Maven repository.

devutility.internal.data.codec.Utf8Utils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
package devutility.internal.data.codec;

import java.io.UnsupportedEncodingException;

public class Utf8Utils {
	/**
	 * Encode value use UTF-8
	 * @param value: String value.
	 * @return byte[]
	 * @throws UnsupportedEncodingException
	 */
	public static byte[] encode(String value) throws UnsupportedEncodingException {
		if (value == null) {
			return null;
		}

		return value.getBytes("UTF-8");
	}

	/**
	 * Decode value use UTF-8
	 * @param bytes: Bytes array
	 * @return String
	 * @throws UnsupportedEncodingException
	 */
	public static String decode(byte[] bytes) throws UnsupportedEncodingException {
		if (bytes == null || bytes.length == 0) {
			return null;
		}

		return new String(bytes, "UTF-8");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy