package net.sf.fast.ibatis.util; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Text; public class Helper { public static final String N_A = "N/A"; public static boolean isNotEmpty(String str) { return str != null && str.trim().length() > 0; } public static boolean isEmptyOrNA(String str) { return !isNotEmpty(str) || !isNotNA(str); } public static boolean isNotNA(String str) { return str != null && !str.equals(N_A); } public static void setTextWidth(Text text, int width) { GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; gridData.widthHint = width; text.setLayoutData(gridData); } public static final String getExceptionStackTrace(Throwable e) { StringWriter stringWriter = new StringWriter(); PrintWriter stackTraceWriter = new PrintWriter(stringWriter); e.printStackTrace(stackTraceWriter); return stringWriter.toString(); } public static final String getString(InputStream in) throws IOException { InputStreamReader is = new InputStreamReader(in); StringBuilder sb=new StringBuilder(); BufferedReader br = new BufferedReader(is); String read = br.readLine(); while(read != null) { //System.out.println(read); sb.append(read); read =br.readLine(); } return sb.toString(); } public static String formatPath(String path) { return path.replaceAll(" ", "_"); } public static void closeQuietly(InputStream is) { try { if (is != null) { is.close(); } } catch (Exception e) { e.printStackTrace(); } } public static void closeQuietly(OutputStream out) { try { if (out != null) { out.close(); } } catch (Exception e) { e.printStackTrace(); } } }