OSDN Git Service

4f28d69ea445684e50a36cffb59a25a16e9bc30f
[rapideact/rapideact.git] / com / rapide_act / CmnUtils.java
1 package com.rapide_act;
2
3 import java.io.BufferedInputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.File;
8 import java.io.FileReader;
9 import java.io.FileWriter;
10 import java.io.BufferedWriter;
11 import java.io.BufferedReader;
12 import java.io.PrintWriter;
13 import java.io.PrintWriter;
14 import java.io.ByteArrayOutputStream;
15 import java.util.Date;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.Properties;
19 import java.util.regex.Pattern;
20 import java.util.regex.Matcher;
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.sql.ResultSet;
24 import java.sql.ResultSetMetaData;
25 import java.sql.SQLException;
26 import java.sql.PreparedStatement;
27 import java.sql.Timestamp;
28 import java.sql.Blob;
29 import java.sql.Clob;
30 import java.math.BigDecimal;
31 import java.math.BigInteger;
32 import java.util.regex.Pattern;
33 import org.apache.commons.codec.binary.Base64;
34 import java.nio.charset.Charset;
35
36 public class CmnUtils{
37         
38         protected static void writeCsv(String _file, int _columnCount, ArrayList<String> _alData) throws Exception{
39                 PrintWriter pw = null;
40                 try {
41                         debugPrint("Start write csv," + "columnCount=" + _columnCount);
42                         pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
43                         for(int i=0;i<_alData.size();i++){
44                                 pw.print(_alData.get(i).replaceAll("\n","\r\n"));
45                                 if (_columnCount == 1){
46                                         pw.println("");
47                                 } else {
48                                         if ((i+1) % _columnCount == 0 && i > 0){
49                                                 pw.println("");
50                                         } else {
51                                                 pw.print(",");
52                                         }
53                                 }
54                         }
55                         pw.close();
56                         debugPrint("End write csv");
57                 }
58                 catch (Exception e){
59                         throw e;
60                 }
61         }
62
63         protected static void writeSeparator(String _file, int _columnCount, ArrayList<String> _alData, String _sprtr) throws Exception{
64                 PrintWriter pw = null;
65                 try {
66                         debugPrint("Start write Separator," + "columnCount=" + _columnCount);
67                         pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
68                         for(int i=0;i<_alData.size();i++){
69                                 pw.print(_alData.get(i).replaceAll("\n","\r\n"));
70                                 if (_columnCount == 1){
71                                         pw.println("");
72                                 } else {
73                                         if ((i+1) % _columnCount == 0 && i > 0){
74                                                 pw.println("");
75                                         } else {
76                                                 pw.print(_sprtr);
77                                         }
78                                 }
79                         }
80                         pw.close();
81                         debugPrint("End write Separator");
82                 }
83                 catch (Exception e){
84                         throw e;
85                 }
86         }
87
88         protected static void printConsole(int _columnCount, ArrayList<String> _alData) throws Exception{
89                 try {
90                         debugPrint("Start console print");
91                         for(int i=0;i<_alData.size();i++){
92                                 System.out.print(_alData.get(i).replaceAll("\n","\r\n"));
93                                 if (_columnCount == 1){
94                                         System.out.println("");
95                                 } else {
96                                         if ((i+1) % _columnCount == 0 && i > 0){
97                                                 System.out.println("");
98                                         } else {
99                                                 System.out.print(",");
100                                         }
101                                 }
102                         }
103                         debugPrint("End console print");
104                 }
105                 catch (Exception e){
106                         throw e;
107                 }
108         }
109
110         protected static void deepPrint(String _message) throws Exception{
111                 if(System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y"))System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
112         }
113
114         protected static void debugPrint(String _message) throws Exception{
115                 if(
116                         (System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y")) || 
117                         (System.getProperty("debug")!=null && System.getProperty("debug").toUpperCase().equals("Y"))
118                 )System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
119         }
120
121         protected static void debugPrinting(String _message) throws Exception{
122                 if(
123                         (System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y")) || 
124                         (System.getProperty("debug")!=null && System.getProperty("debug").toUpperCase().equals("Y"))
125                 )System.out.print(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
126         }
127
128         protected static void infoPrint(String _message) throws Exception{
129                 System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [INFO] " + _message);
130         }
131         protected static void infoPrinting(String _message) throws Exception{
132                 System.out.print(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [INFO] " + _message);
133         }
134
135         protected static void errorPrint(String _message) throws Exception{
136                 System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [ERROR] " + _message);
137         }
138
139         protected static String getTimestamp() throws Exception{
140                 return (new java.text.SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
141         }
142
143         protected static String getYmdhm() throws Exception{
144                 return (new java.text.SimpleDateFormat("yyyyMMddHHmm").format(new Date()));
145         }
146
147         protected static int getArrayRowNo(ArrayList<String> _al, int _alMember, int _seq, String _value) throws Exception {
148                 int ret = -1;
149                 for(int i=0;i<_al.size()/_alMember;i++){
150                         if(_al.get(i*_alMember + _seq).equals(_value)){
151                                 ret = i;
152                                 break;
153                         }
154                 }
155                 return ret;
156         }
157
158         protected static String [] getArrayRowData(ArrayList<String> _al, int _alMember, int _row) throws Exception {
159                 String [] rowData = new String[_alMember];
160                 int colNo = 0;
161                 for(int i=_row*_alMember;i<_row*_alMember + _alMember;i++){
162                         rowData[colNo] = _al.get(i);
163                         colNo++;
164                 }
165                 return rowData;
166         }
167
168         protected static String [] splitCsv(String _line) throws Exception {
169                 return split(_line, ",");
170         }
171
172         protected static String [] splitSpace(String _line) throws Exception {
173                 return split(_line, " ");
174         }
175
176         protected static String [] splitDot(String _line) throws Exception {
177                 return split(_line, "\\.");
178         }
179         
180         protected static String [] splitCrLf(String _line) throws Exception {
181                 return split(_line, "\r\n");
182         }
183
184         protected static String [] splitSlash(String _line) throws Exception {
185                 return split(_line, "/");
186         }
187
188         protected static String [] splitTab(String _line) throws Exception {
189                 return split(_line, "\t");
190         }
191
192         protected static String [] split(String _line, String _delim) throws Exception {
193                 String [] strSplit;
194                 strSplit = _line.split(_delim, -1);
195                 return strSplit;
196         }
197         
198         protected static boolean isLastCrLf(String _str) throws Exception{
199                 boolean rtn = false;
200                 char[] charArray = _str.toCharArray();
201                 if (_str.length() > 1){
202                         if (charArray[_str.length() - 2] != '\r' && charArray[_str.length() - 1] != '\n'){
203                                 rtn = true;
204                         }
205                 }
206                 return rtn;
207         }
208
209         protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
210         protected static String bytesToHex(byte[] _bytes){
211                 char[] hexChars = new char[_bytes.length * 2];
212                 for(int j=0;j<_bytes.length;j++){
213                         int v = _bytes[j] & 0xFF;
214                         hexChars[j * 2] = hexArray[v >>> 4];
215                         hexChars[j * 2 + 1] = hexArray[v & 0x0F];
216                 }
217                 return new String(hexChars);
218         }
219         protected static byte[] hexToBytes(String _hex){
220                 byte[] bytes = new byte[_hex.length()/2];
221                 for(int j=0;j<_hex.length()/2;j++){
222                         bytes[j] = (byte)Integer.parseInt(_hex.substring(j*2,(j+1)*2),16);
223                 }
224                 return bytes;
225         }
226
227         protected static String bytesToBase64(byte[] _bytes){
228                 return new String(Base64.encodeBase64(_bytes));
229         }
230         protected static byte[] base64ToBytes(String _base64){
231                 return Base64.decodeBase64(_base64.getBytes());
232         }
233
234         protected static String clobToString(Clob _clob) throws Exception{
235                 return _clob.getSubString(1, (int)_clob.length());
236         }
237
238         protected static String getLineSeparator(){
239                 return System.getProperty("line.separator");
240         }
241
242         protected static boolean isMatch(String [] _tables, String _table) throws Exception{
243                 boolean rtn = false;
244                 Pattern p = null;
245                 Matcher m = null;
246                 if(_tables != null && _tables.length>0){
247                         for (int i = 0; i < _tables.length; i++) {
248                                 String s = _tables[i].replace("*",".*");
249                                 //debugPrint("s="+s);
250                                 //p = Pattern.compile(s);
251                                 //m = p.matches(_table);
252                                 if(_table.matches(s)){
253                                         rtn = true;
254                                         break;
255                                 }
256                         }
257                 }
258                 return rtn;
259         }
260         
261         protected static String getYesNo(boolean _bln){
262                 String retVal;
263                 if(_bln){
264                         retVal = "Yes";
265                 } else {
266                         retVal = "No";
267                 }
268                 return retVal;
269         }
270
271         protected static boolean isMatch(String [] _tabCols, String _table, String _col) throws Exception{
272                 boolean rtn = false;
273                 Pattern p = null;
274                 Matcher m = null;
275                 if(_tabCols != null && _tabCols.length>0){
276                         for (int i = 0; i < _tabCols.length; i++) {
277                                 String s = null;
278                                 String [] tbCols = splitDot(_tabCols[i]);
279                                 //infoPrint("length="+tbCols.length);
280                                 if (tbCols.length == 1){
281                                         s = _tabCols[i].replace("*",".*");
282                                         if(_col.matches(s)){
283                                                 rtn = true;
284                                                 break;
285                                         }
286                                 } else if (tbCols.length == 2){
287                                         if(_table.matches(tbCols[0].replace("*",".*")) && _col.matches(tbCols[1].replace("*",".*"))){
288                                                 rtn = true;
289                                                 break;
290                                         }
291                                 }
292                         }
293                 }
294                 return rtn;
295         }
296
297         protected static boolean isJapanese(String _str) throws Exception{
298                 for(int i=0;i<_str.length();i++){
299                         char chr = _str.charAt(i);
300                         Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(chr);
301                         if (Character.UnicodeBlock.HIRAGANA.equals(unicodeBlock))return true;
302                         if (Character.UnicodeBlock.KATAKANA.equals(unicodeBlock))return true;
303                         if (Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS.equals(unicodeBlock))return true;
304                         if (Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(unicodeBlock))return true;
305                         if (Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION.equals(unicodeBlock))return true;
306                 }
307                 return false;
308         }
309
310         protected static boolean isHankaku(char _chr) throws Exception{
311                 if((_chr <= '\u007e') || (_chr == '\u00a5') || (_chr == '\u203e') || (_chr >= '\uff61' && _chr <= '\uff9f')){
312                         return true;
313                 } else {
314                         return false;
315                 }
316         }
317
318         protected static boolean isColLength(String _colType) throws Exception{
319                 if(
320                         _colType.toUpperCase().equals("RAW") ||
321                         _colType.toUpperCase().equals("BINARY") ||
322                         _colType.toUpperCase().equals("VARBINARY") ||
323                         _colType.toUpperCase().equals("CHAR") ||
324                         _colType.toUpperCase().equals("NCHAR") || 
325                         _colType.toUpperCase().equals("VARCHAR") || 
326                         _colType.toUpperCase().equals("VARCHAR2") || 
327                         _colType.toUpperCase().equals("NVARCHAR") || 
328                         _colType.toUpperCase().equals("NVARCHAR2")
329                 ){
330                         return true;
331                 } else {
332                         return false;
333                 }
334         }
335
336         protected static boolean isColPrec(String _colType, String _colPrec) throws Exception{
337                 if(
338                         !_colPrec.equals("") && 
339                         !_colPrec.equals("0") && 
340                         (
341                                 _colType.toUpperCase().equals("DECIMAL") ||
342                                 _colType.toUpperCase().equals("NUMBER") || 
343                                 _colType.toUpperCase().equals("NUMERIC")
344                         )
345                 ){
346                         return true;
347                 } else {
348                         return false;
349                 }
350         }
351
352         protected static int getColLength(String _colType, String _colLen) throws Exception{
353                 if(
354                         _colType.toUpperCase().equals("NCHAR") ||
355                         _colType.toUpperCase().equals("NVARCHAR") ||
356                         _colType.toUpperCase().equals("NVARCHAR2")){
357                                 return Integer.parseInt(_colLen)/2;
358                 } else {
359                         return Integer.parseInt(_colLen);
360                 }
361         }
362
363         protected static boolean isColString(String _str) throws Exception{
364                 if(
365                         _str.toUpperCase().equals("LONG") ||
366                         _str.toUpperCase().equals("XML") ||
367                         _str.toUpperCase().equals("UNIQUEIDENTIFIER") ||
368                         _str.toUpperCase().equals("TEXT") ||
369                         _str.toUpperCase().equals("NTEXT") ||
370                         _str.toUpperCase().equals("CHARACTER") ||
371                         _str.toUpperCase().equals("CHAR") ||
372                         _str.toUpperCase().equals("BPCHAR") ||
373                         _str.toUpperCase().equals("NCHAR") ||
374                         _str.toUpperCase().equals("VARCHAR") ||
375                         _str.toUpperCase().equals("VARCHAR2") ||
376                         _str.toUpperCase().equals("NVARCHAR") ||
377                         _str.toUpperCase().equals("NVARCHAR2") ||
378                         _str.toUpperCase().equals("LONG VARCHAR") ||
379                         _str.toUpperCase().equals("GRAPHIC") ||
380                         _str.toUpperCase().equals("VARGRAPHIC") ||
381                         _str.toUpperCase().equals("LONG VARGRAPHIC") ||
382                         _str.toUpperCase().equals("MVARCHAR")){
383                         return true;
384                 } else {
385                         return false;
386                 }
387         }
388
389         protected static boolean isColBoolean(String _str) throws Exception{
390                 if(
391                         _str.toUpperCase().equals("BIT") ||
392                         _str.toUpperCase().equals("BOOL") ||
393                         _str.toUpperCase().equals("BOOLEAN")){
394                         return true;
395                 } else {
396                         return false;
397                 }
398         }
399
400         protected static boolean isColDate(String _str) throws Exception{
401                 if(
402                         _str.toUpperCase().equals("DATE")){
403                         return true;
404                 } else {
405                         return false;
406                 }
407         }
408
409         protected static boolean isColYear(String _str) throws Exception{
410                 if(
411                 _str.toUpperCase().equals("YEAR")){
412                         return true;
413                 } else {
414                         return false;
415                 }
416         }
417
418         protected static boolean isColTime(String _str) throws Exception{
419                 if(
420                         _str.toUpperCase().equals("TIME")){
421                         return true;
422                 } else {
423                         return false;
424                 }
425         }
426
427         protected static boolean isColTimestamp(String _str) throws Exception{
428                 if(
429                         _str.toUpperCase().equals("TIMESTAMP") ||
430                         _str.toUpperCase().equals("SMALLDATETIME") ||
431                         _str.toUpperCase().equals("DATETIME") ||
432                         _str.toUpperCase().equals("DATETIME2")){
433                         return true;
434                 } else {
435                         return false;
436                 }
437         }
438
439         protected static boolean isColBigDecimal(String _str) throws Exception{
440                 if(
441                         _str.toUpperCase().equals("NUMERIC") ||
442                         _str.toUpperCase().equals("NUMBER") ||
443                         _str.toUpperCase().equals("MONEY") ||
444                         _str.toUpperCase().equals("SMALLMONEY") ||
445                         _str.toUpperCase().equals("DECFLOAT") ||
446                         _str.toUpperCase().equals("DECIMAL")){
447                         return true;
448                 } else {
449                         return false;
450                 }
451         }
452
453         protected static boolean isColShort(String _str) throws Exception{
454                 if(
455                         _str.toUpperCase().equals("TINYINT") ||
456                         _str.toUpperCase().equals("TINYINT UNSIGNED") ||
457                         _str.toUpperCase().equals("SMALLINT")){
458                         return true;
459                 } else {
460                         return false;
461                 }
462         }
463
464         protected static boolean isColInt(String _str) throws Exception{
465                 if(
466                         _str.toUpperCase().equals("INTEGER") ||
467                         _str.toUpperCase().equals("SMALLINT UNSIGNED") ||
468                         _str.toUpperCase().equals("MEDIUMINT") ||
469                         _str.toUpperCase().equals("SERIAL") ||
470                         _str.toUpperCase().equals("INT2") ||
471                         _str.toUpperCase().equals("INT4") ||
472                         _str.toUpperCase().equals("INT")){
473                         return true;
474                 } else {
475                         return false;
476                 }
477         }
478
479         protected static boolean isColLong(String _str) throws Exception{
480                 if(
481                         _str.toUpperCase().equals("INTEGER UNSIGNED") ||
482                         _str.toUpperCase().equals("MEDIUMINT UNSIGNED") ||
483                         _str.toUpperCase().equals("BIGINT UNSIGNED") ||
484                         _str.toUpperCase().equals("BIGINT") ||
485                         _str.toUpperCase().equals("BIGSERIAL") ||
486                         _str.toUpperCase().equals("SERIAL8") ||
487                         _str.toUpperCase().equals("INT8")){
488                         return true;
489                 } else {
490                         return false;
491                 }
492         }
493
494         protected static boolean isColFloat(String _str) throws Exception{
495                 if(
496                         _str.toUpperCase().equals("REAL") ||
497                         _str.toUpperCase().equals("SMALLFLT")){
498                         return true;
499                 } else {
500                         return false;
501                 }
502         }
503
504         protected static boolean isColDouble(String _str) throws Exception{
505                 if(
506                         _str.toUpperCase().equals("FLOAT") ||
507                         _str.toUpperCase().equals("DOUBLE") ||
508                         _str.toUpperCase().equals("DOUBLE PRECISION")){
509                         return true;
510                 } else {
511                         return false;
512                 }
513         }
514
515         protected static boolean isColBytes(String _str) throws Exception{
516                 if(
517                         _str.toUpperCase().equals("RAW") ||
518                         _str.toUpperCase().equals("GEOMETRY") ||
519                         _str.toUpperCase().equals("BINARY")){
520                         return true;
521                 } else {
522                         return false;
523                 }
524         }
525
526         protected static boolean isColBlob(String _str) throws Exception{
527                 if(
528                         _str.toUpperCase().equals("BYTEA") ||
529                         _str.toUpperCase().equals("BLOB") ||
530                         _str.toUpperCase().equals("VARBINARY") ||
531                         _str.toUpperCase().equals("UDT") ||
532                         _str.toUpperCase().equals("IMAGE")){
533                         return true;
534                 } else {
535                         return false;
536                 }
537         }
538
539         protected static boolean isColClob(String _str) throws Exception{
540                 if(
541                         _str.toUpperCase().equals("CLOB") ||
542                         _str.toUpperCase().equals("NCLOB")){
543                         return true;
544                 } else {
545                         return false;
546                 }
547         }
548
549         protected static boolean isLob(String _str) throws Exception{
550                 if(
551                         isColClob(_str) || isColBlob(_str)){
552                         return true;
553                 } else {
554                         return false;
555                 }
556         }
557
558         protected static boolean isEmpty(String _str) throws Exception{
559                 if(_str == null || _str.equals("")){
560                         return true;
561                 } else {
562                         return false;
563                 }
564         }
565
566         protected static boolean isNumeric(String _str) {
567                 boolean retVal = true;
568                 try {
569                         int val = Integer.parseInt(_str);
570                 } catch (Exception e){
571                         retVal = false;
572                 }
573                 return retVal;
574         }
575
576         protected static String[] getSystemProperty(String _str) throws Exception{
577                 String [] retValue = null;
578                 if(System.getProperty(_str)!=null){
579                         retValue = splitCsv(System.getProperty(_str).toUpperCase());
580                 }
581                 return retValue;
582         }
583
584         protected static String getSystemProperty(String _str, String _strDefault) throws Exception{
585                 String retValue = _strDefault;
586                 if(System.getProperty(_str)!=null){
587                         retValue = System.getProperty(_str).toUpperCase();
588                 }
589                 return retValue;
590         }
591
592         protected static char getSystemProperty(String _str, char _chrDefault) throws Exception{
593                 char retValue = _chrDefault;
594                 if(System.getProperty(_str)!=null){
595                         retValue = System.getProperty(_str).toUpperCase().charAt(0);
596                 }
597                 return retValue;
598         }
599
600         protected static boolean getSystemProperty(String _str, boolean _blnDefault) throws Exception{
601                 boolean retValue = _blnDefault;
602                 if(System.getProperty(_str)!=null){
603                         if(System.getProperty(_str).toUpperCase().equals("Y")){
604                                 retValue = true;
605                         } else if (System.getProperty(_str).toUpperCase().equals("N")){
606                                 retValue = false;
607                         } else {
608                                 retValue = true;
609                         }
610                 }
611                 return retValue;
612         }
613
614         protected static String getSeparator(String _str, String _strDefault) throws Exception{
615                 String retValue = _strDefault;
616                 if(System.getProperty(_str)!=null){
617                         String _sprtr = System.getProperty(_str);
618                         char [] chr = new char[_sprtr.length()];
619                         int j = 0;
620                         for(int i=0;i<_sprtr.length();i++){
621                                 if (i < _sprtr.length() - 1){
622                                         if (_sprtr.charAt(i) == '\\'){
623                                                 switch(_sprtr.charAt(i + 1)){
624                                                         case 't':
625                                                                 chr[j] = 0x09;
626                                                                 i++;
627                                                                 j++;
628                                                                 break;
629                                                         default:
630                                                                 chr[j] = _sprtr.charAt(i);
631                                                                 j++;
632                                                                 break;
633                                                 }
634                                         } else {
635                                                 chr[j] = _sprtr.charAt(i);
636                                                 j++;
637                                         }
638                                 } else {
639                                         chr[j] = _sprtr.charAt(i);
640                                         j++;
641                                 }
642                         }
643                         char [] chr2 = new char[j];
644                         for(int i=0;i<j;i++){
645                                 chr2[i] = chr[i];
646                         }
647                         retValue = String.valueOf(chr2);
648                 }
649                 return retValue;
650         }
651
652         protected static String getDelimiter(String _str) throws Exception{
653                 String retValue = _str;
654                 if(_str!=null){
655                         char [] chr = new char[_str.length()];
656                         int j = 0;
657                         for(int i=0;i<_str.length();i++){
658                                 if (i < _str.length() - 1){
659                                         if (_str.charAt(i) == '\\'){
660                                                 switch(_str.charAt(i + 1)){
661                                                         case 't':
662                                                                 chr[j] = 0x09;
663                                                                 i++;
664                                                                 j++;
665                                                                 break;
666                                                         default:
667                                                                 chr[j] = _str.charAt(i);
668                                                                 j++;
669                                                                 break;
670                                                 }
671                                         } else {
672                                                 chr[j] = _str.charAt(i);
673                                                 j++;
674                                         }
675                                 } else {
676                                         chr[j] = _str.charAt(i);
677                                         j++;
678                                 }
679                         }
680                         char [] chr2 = new char[j];
681                         for(int i=0;i<j;i++){
682                                 chr2[i] = chr[i];
683                         }
684                         retValue = String.valueOf(chr2);
685                 }
686                 return retValue;
687         }
688
689         protected static String getLineSeparator(String _str, String _strDefault) throws Exception{
690                 String retValue = _strDefault;
691                 if(System.getProperty(_str)!=null){
692                         String _sprtr = System.getProperty(_str);
693                         char [] chr = new char[_sprtr.length()];
694                         int j = 0;
695                         for(int i=0;i<_sprtr.length();i++){
696                                 if (i < _sprtr.length() - 1){
697                                         if (_sprtr.charAt(i) == '\\'){
698                                                 switch(_sprtr.charAt(i + 1)){
699                                                         case 'r':
700                                                                 chr[j] = 0x0d;
701                                                                 i++;
702                                                                 j++;
703                                                                 break;
704                                                         case 'n':
705                                                                 chr[j] = 0x0a;
706                                                                 i++;
707                                                                 j++;
708                                                                 break;
709                                                 }
710                                         }
711                                 }
712                         }
713                         char [] chr2 = new char[j];
714                         for(int i=0;i<j;i++){
715                                 chr2[i] = chr[i];
716                         }
717                         retValue = String.valueOf(chr2);
718                 }
719                 return retValue;
720         }
721
722         protected static String getLineSeparator(String _str) throws Exception{
723                 String retValue = _str;
724                 if(_str!=null){
725                         char [] chr = new char[_str.length()];
726                         int j = 0;
727                         for(int i=0;i<_str.length();i++){
728                                 if (i < _str.length() - 1){
729                                         if (_str.charAt(i) == '\\'){
730                                                 switch(_str.charAt(i + 1)){
731                                                         case 'r':
732                                                                 chr[j] = 0x0d;
733                                                                 i++;
734                                                                 j++;
735                                                                 break;
736                                                         case 'n':
737                                                                 chr[j] = 0x0a;
738                                                                 i++;
739                                                                 j++;
740                                                                 break;
741                                                 }
742                                         }
743                                 }
744                         }
745                         char [] chr2 = new char[j];
746                         for(int i=0;i<j;i++){
747                                 chr2[i] = chr[i];
748                         }
749                         retValue = String.valueOf(chr2);
750                 }
751                 return retValue;
752         }
753
754         protected static boolean isFixString(String _str) throws Exception{
755                 if(
756                         _str.toUpperCase().equals("CHARACTER") ||
757                         _str.toUpperCase().equals("CHAR") ||
758                         _str.toUpperCase().equals("NCHAR")){
759                         return true;
760                 } else {
761                         return false;
762                 }
763         }
764
765         protected static int getByteLength(String string, Charset charset) {
766                 return string.getBytes(charset).length;
767         }
768
769         protected static String padSpace(String str, int len, Charset charset){
770                 int bytelen = getByteLength(str, charset);
771                 if(len > bytelen){
772                         for(int i=0; i<(len - bytelen);i++){
773                             str = str + " ";
774                         }
775                 }
776                 return str;
777         }
778
779 }