import java.math.BigInteger;
import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Base64;
+import java.nio.charset.Charset;
public class CmnUtils{
+ protected static void emptyFile(String _file) throws Exception{
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
+ pw.close();
+ }
+ catch (Exception e){
+ throw e;
+ }
+ }
+
protected static void writeCsv(String _file, int _columnCount, ArrayList<String> _alData) throws Exception{
PrintWriter pw = null;
try {
}
}
+ protected static void writeSeparator(String _file, int _columnCount, ArrayList<String> _alData, String _sprtr) throws Exception{
+ PrintWriter pw = null;
+ try {
+ debugPrint("Start write Separator," + "columnCount=" + _columnCount);
+ pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
+ for(int i=0;i<_alData.size();i++){
+ pw.print(_alData.get(i).replaceAll("\n","\r\n"));
+ if (_columnCount == 1){
+ pw.println("");
+ } else {
+ if ((i+1) % _columnCount == 0 && i > 0){
+ pw.println("");
+ } else {
+ pw.print(_sprtr);
+ }
+ }
+ }
+ pw.close();
+ debugPrint("End write Separator");
+ }
+ catch (Exception e){
+ throw e;
+ }
+ }
+
protected static void printConsole(int _columnCount, ArrayList<String> _alData) throws Exception{
try {
debugPrint("Start console print");
}
}
+ protected static boolean isColLength(String _colType) throws Exception{
+ if(
+ _colType.toUpperCase().equals("RAW") ||
+ _colType.toUpperCase().equals("BINARY") ||
+ _colType.toUpperCase().equals("VARBINARY") ||
+ _colType.toUpperCase().equals("CHAR") ||
+ _colType.toUpperCase().equals("NCHAR") ||
+ _colType.toUpperCase().equals("VARCHAR") ||
+ _colType.toUpperCase().equals("VARCHAR2") ||
+ _colType.toUpperCase().equals("NVARCHAR") ||
+ _colType.toUpperCase().equals("NVARCHAR2")
+ ){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected static boolean isColPrec(String _colType, String _colPrec) throws Exception{
+ if(
+ !_colPrec.equals("") &&
+ !_colPrec.equals("0") &&
+ (
+ _colType.toUpperCase().equals("DECIMAL") ||
+ _colType.toUpperCase().equals("NUMBER") ||
+ _colType.toUpperCase().equals("NUMERIC")
+ )
+ ){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected static int getColLength(String _colType, String _colLen) throws Exception{
+ if(
+ _colType.toUpperCase().equals("NCHAR") ||
+ _colType.toUpperCase().equals("NVARCHAR") ||
+ _colType.toUpperCase().equals("NVARCHAR2")){
+ return Integer.parseInt(_colLen)/2;
+ } else {
+ return Integer.parseInt(_colLen);
+ }
+ }
+
protected static boolean isColString(String _str) throws Exception{
if(
+ _str.toUpperCase().equals("LONG") ||
_str.toUpperCase().equals("XML") ||
_str.toUpperCase().equals("UNIQUEIDENTIFIER") ||
_str.toUpperCase().equals("TEXT") ||
_str.toUpperCase().equals("NTEXT") ||
+ _str.toUpperCase().equals("CHARACTER") ||
_str.toUpperCase().equals("CHAR") ||
+ _str.toUpperCase().equals("BPCHAR") ||
_str.toUpperCase().equals("NCHAR") ||
_str.toUpperCase().equals("VARCHAR") ||
_str.toUpperCase().equals("VARCHAR2") ||
_str.toUpperCase().equals("NVARCHAR") ||
_str.toUpperCase().equals("NVARCHAR2") ||
+ _str.toUpperCase().equals("LONG VARCHAR") ||
+ _str.toUpperCase().equals("GRAPHIC") ||
+ _str.toUpperCase().equals("VARGRAPHIC") ||
+ _str.toUpperCase().equals("LONG VARGRAPHIC") ||
_str.toUpperCase().equals("MVARCHAR")){
return true;
} else {
}
}
+ protected static boolean isColBoolean(String _str) throws Exception{
+ if(
+ _str.toUpperCase().equals("BIT") ||
+ _str.toUpperCase().equals("BOOL") ||
+ _str.toUpperCase().equals("BOOLEAN")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
protected static boolean isColDate(String _str) throws Exception{
if(
_str.toUpperCase().equals("DATE")){
_str.toUpperCase().equals("NUMBER") ||
_str.toUpperCase().equals("MONEY") ||
_str.toUpperCase().equals("SMALLMONEY") ||
+ _str.toUpperCase().equals("DECFLOAT") ||
_str.toUpperCase().equals("DECIMAL")){
return true;
} else {
_str.toUpperCase().equals("INTEGER") ||
_str.toUpperCase().equals("SMALLINT UNSIGNED") ||
_str.toUpperCase().equals("MEDIUMINT") ||
+ _str.toUpperCase().equals("SERIAL") ||
+ _str.toUpperCase().equals("INT2") ||
+ _str.toUpperCase().equals("INT4") ||
_str.toUpperCase().equals("INT")){
return true;
} else {
_str.toUpperCase().equals("MEDIUMINT UNSIGNED") ||
_str.toUpperCase().equals("BIGINT UNSIGNED") ||
_str.toUpperCase().equals("BIGINT") ||
- _str.toUpperCase().equals("LONG")){
+ _str.toUpperCase().equals("BIGSERIAL") ||
+ _str.toUpperCase().equals("SERIAL8") ||
+ _str.toUpperCase().equals("INT8")){
return true;
} else {
return false;
protected static boolean isColDouble(String _str) throws Exception{
if(
_str.toUpperCase().equals("FLOAT") ||
+ _str.toUpperCase().equals("DOUBLE") ||
_str.toUpperCase().equals("DOUBLE PRECISION")){
return true;
} else {
protected static boolean isColBlob(String _str) throws Exception{
if(
+ _str.toUpperCase().equals("BYTEA") ||
_str.toUpperCase().equals("BLOB") ||
_str.toUpperCase().equals("VARBINARY") ||
_str.toUpperCase().equals("UDT") ||
return retVal;
}
+ protected static boolean isReserved(String _str) throws Exception{
+ if(
+ _str.toUpperCase().equals("CURRENT_DATE") ||
+ _str.toUpperCase().equals("CURRENT_TIME") ||
+ _str.toUpperCase().equals("CURRENT_TIMESTAMP") ||
+ _str.toUpperCase().equals("CURRENT_USER") ||
+ _str.toUpperCase().equals("LOCALTIME") ||
+ _str.toUpperCase().equals("LOCALTIMESTAMP") ||
+ _str.toUpperCase().equals("NULL")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
protected static String[] getSystemProperty(String _str) throws Exception{
String [] retValue = null;
if(System.getProperty(_str)!=null){
return retValue;
}
+ protected static boolean isFixString(String _str) throws Exception{
+ if(
+ _str.toUpperCase().equals("CHARACTER") ||
+ _str.toUpperCase().equals("CHAR") ||
+ _str.toUpperCase().equals("NCHAR")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected static int getByteLength(String string, Charset charset) {
+ return string.getBytes(charset).length;
+ }
+
+ protected static String padSpace(String str, int len, Charset charset){
+ int bytelen = getByteLength(str, charset);
+ if(len > bytelen){
+ for(int i=0; i<(len - bytelen);i++){
+ str = str + " ";
+ }
+ }
+ return str;
+ }
+
}