OSDN Git Service

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