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

org.subethamail.smtp.util.TextUtils Maven / Gradle / Ivy

There is a newer version: 3.1.7
Show newest version
package org.subethamail.smtp.util;

import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author Jeff Schnitzer
 */
public class TextUtils
{
	/**
	 * @return a delimited string containing the specified items
	 */
	public static String joinTogether(Collection items, String delim)
	{
		StringBuffer ret = new StringBuffer();

		for (Iterator it=items.iterator(); it.hasNext();)
		{
			ret.append(it.next());
			if (it.hasNext())
			{
				ret.append(delim);
			}
		}

		return ret.toString();
	}

	/**
	 * @return the value of str.getBytes() without the idiotic checked exception
	 */
	public static byte[] getBytes(String str, String charset)
	{
		try
		{
			return str.getBytes(charset);
		}
		catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); }
	}
	
	/** @return the string as US-ASCII bytes */
	public static byte[] getAsciiBytes(String str)
	{
		return getBytes(str, "US-ASCII");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy