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

com.github.antelopeframework.util.SafeEncoder Maven / Gradle / Ivy

The newest version!
package com.github.antelopeframework.util;

import java.io.UnsupportedEncodingException;

import com.github.antelopeframework.BizRuntimeException;

public class SafeEncoder {
	public static final String CHARSET = "UTF-8";
	
	public static byte[][] encodeMany(final String... strs) {
		byte[][] many = new byte[strs.length][];
		for (int i = 0; i < strs.length; i++) {
			many[i] = encode(strs[i]);
		}
		
		return many;
	}

	public static byte[] encode(final String str) {
		try {
			if (str == null) {
				throw new IllegalArgumentException("value sent to queue cannot be null");
			}
			
			return str.getBytes(CHARSET);
		} catch (UnsupportedEncodingException e) {
			throw new BizRuntimeException(e);
		}
	}

	public static String encode(final byte[] data) {
		try {
			return new String(data, CHARSET);
		} catch (UnsupportedEncodingException e) {
			throw new BizRuntimeException(e);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy