1 package com.daffodilwoods.daffodildb.utils.byteconverter; 2 3 import com.daffodilwoods.database.general.*; 4 import java.util.Arrays ; 5 import com.daffodilwoods.database.resource.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype; 7 import java.io.*; 8 import com.daffodilwoods.daffodildb.utils.BufferRange; 9 import com.daffodilwoods.database.utility.P; 10 11 public class CCzufDpowfsufs implements Datatype 12 { 13 14 public static byte[] getBytes(String str , int length,boolean collator) { 15 try { 16 if (str == null ) 17 return null; 18 if(length == -1) 19 return str.getBytes(collator ? "UTF16" : "ISO-8859-1"); 20 int len = str.length(); 21 if(len < length){ 22 char pad_Char = ' '; 23 for (int i = 0,k= length-len; i < k ; i++) 24 str += pad_Char; 25 } 26 byte[] b1 = str.getBytes(collator ? "UTF16" : "ISO-8859-1"); 27 return b1; 28 } 29 30 catch (UnsupportedEncodingException ex) { 31 return null; 32 } 33 } 34 35 public static byte[] getBytes(Boolean b) { 36 if( b== null) 37 return null; 38 byte bvalue = Boolean.TRUE.equals(b) ? (byte)1 :(byte)0; 39 return new byte[]{bvalue}; 40 } 41 42 43 44 public static byte[] getBytes(Integer a){ 45 if( a == null ) 46 return null; 47 byte b[] = new byte[4]; 48 int a1 = a.intValue(); 49 for(int i = 24,j=0; i >= 0 ; i-=8 ) 50 b[j++] =(byte) ((a1 >> i) & 0xFF); 51 return b; 52 } 53 54 public static byte[] getBytes(Short a) { 55 if( a == null) 56 return null; byte b[]=new byte[2]; 58 short a1 = a.shortValue(); 59 b[0] = (byte)(( (a1 >>> 8)) & 0xFF); 60 b[1] = (byte)(( (a1 >>> 0)) & 0xFF); 61 return b; 62 } 63 64 public static byte[] getBytes( Long a ) 65 { 66 if( a == null) 67 return null; 68 byte b[] = new byte[8]; 69 long a1 = a.longValue(); 70 for(int i = 56 , j=0 ; i >= 0 ; i-= 8) 71 b[j++]=(byte)((a1 >> i) & 0xFF); 72 return b; 73 } 74 75 public static byte[] getBytes( long a ) 76 { 77 byte b[] = new byte[8]; 78 for(int i = 56 , j=0 ; i >= 0 ; i-= 8) 79 b[j++]=(byte)((a >> i) & 0xFF); 80 return b; 81 } 82 83 84 public static byte[] getBytes( java.math.BigDecimal a ) 85 { 86 if( a == null) 87 return null; 88 String str = a.toString(); 89 byte b[] = str.getBytes(); 90 return b; 91 } 92 93 public static byte[] getBytes(Byte byteValue) { 94 return byteValue == null ? null : new byte[] {byteValue.byteValue()}; 95 } 96 97 public static byte[] getBytes(java.sql.Blob blob) { 98 if(blob == null) 99 return null; 100 byte[] bytes = null; 101 try{ 102 bytes = blob.getBytes(1,(int)blob.length()); 103 }catch (java.sql.SQLException ex){ex.printStackTrace();} 104 return bytes; 105 } 106 107 public static byte[] getBytes(java.sql.Clob clob) { 108 byte[] bytes = null; 109 if(clob == null) 110 return null; 111 try{ 112 String str = clob.getSubString(1,(int)clob.length()); 113 bytes = getBytes(str,-1,false); 114 }catch (java.sql.SQLException ex){ex.printStackTrace();} 115 return bytes; 116 } 117 118 public final static Long getLong(byte[] b) 119 { 120 try{ 121 122 123 long a = ((b[7] & 0xFFL) << 0) | 124 ((b[ 6] & 0xFFL) << 8) | 125 ((b[ 5] & 0xFFL) << 16) | 126 ((b[ 4] & 0xFFL) << 24) | 127 ((b[ 3] & 0xFFL) << 32) | 128 ((b[ 2] & 0xFFL) << 40) | 129 ((b[ 1] & 0xFFL) << 48)| 130 ((b[ 0] & 0xFFL) << 56); 131 132 return new Long (a); 133 }catch (NullPointerException ex) { 134 return null; 135 } 136 } 137 138 139 140 public static Byte getByte(byte [] bytes){ 141 142 return bytes == null ? null : new Byte (bytes[0]); 143 } 144 145 public static java.math.BigDecimal getBigDecimal(byte[] bytes) 146 { 147 if( bytes == null) 148 return null; 149 String ss1 = new String ( bytes ); 150 java.math.BigDecimal aa = new java.math.BigDecimal (ss1); 151 return aa; 152 } 153 154 155 public static byte[] getBytes(Float a ) 156 { 157 if( a == null) 158 return null; 159 byte b[] = new byte[4]; 160 float a1 = a.floatValue(); 161 int e = Float.floatToIntBits(a1); 162 for(int i = 24 ,j = 0; i >= 0 ; i-= 8) 163 b[j++]= (byte)((e >> i) & 0xFF); 164 return b; 165 } 166 167 public static byte[] getBytes( float a ) { 168 byte b[] = new byte[4]; 169 int e = Float.floatToIntBits(a); 170 for(int i = 24 ,j = 0; i >= 0 ; i-= 8) 171 b[j++]= (byte)((e >> i) & 0xFF); 172 return b; 173 } 174 175 public static byte[] getBytes(java.util.Date date) 176 { 177 if( date == null) 178 return null; 179 byte b[] = new byte[8]; 180 long a1 = date.getTime(); 181 for(int i = 56 , j=0 ; i >= 0 ; i-= 8) 182 b[j++]=(byte)((a1 >> i) & 0xFF); 183 return b; 184 } 185 186 public static byte[] getBytes(java.sql.Timestamp timestamp) 187 { 188 if( timestamp == null) 189 return null; 190 byte b[] = new byte[8]; 191 long a1 = timestamp.getTime(); 192 for(int i = 56 , j=0 ; i >= 0 ; i-= 8) 193 b[j++]=(byte)((a1 >> i) & 0xFF); 194 return b; 195 } 196 197 public static byte[] getBytes(java.sql.Time time) 198 { 199 if( time == null) 200 return null; 201 202 byte b[] = new byte[8]; 203 long a1 = time.getTime(); 204 for(int i = 56 , j=0 ; i >= 0 ; i-= 8) 205 b[j++]=(byte)((a1 >> i) & 0xFF); 206 return b; 207 } 208 public static Float getFloat(byte[] bytes) 209 { 210 if( bytes == null) 211 return null; 212 int a =((bytes[3] & 0xFF) << 0) | 213 ((bytes[ 2] & 0xFF) << 8) | 214 ((bytes[ 1] & 0xFF) << 16) | 215 ((bytes[ 0] & 0xFF) << 24); 216 217 float f = Float.intBitsToFloat(a); 218 Float ff = new Float (f); 219 return ff; 220 } 221 222 223 224 public static byte[] getBytes( Double a ) 225 { 226 if( a == null) 227 return null; 228 229 byte b[] = new byte[8]; 230 double a1 = a.doubleValue(); 231 long d=Double.doubleToLongBits(a1); 232 for(int i = 56 , j = 0 ; i >= 0 ; i-= 8) 233 b[j++]=(byte)((d >> i) & 0xFF); 234 return b; 235 } 236 237 public static byte[] getBytes( double dbl ) { 238 byte b[] = new byte[8]; 239 long d=Double.doubleToLongBits(dbl); 240 for(int i = 56 , j = 0 ; i >= 0 ; i-= 8) 241 b[j++]=(byte)((d >> i) & 0xFF); 242 return b; 243 244 } 245 246 247 public static Double getDouble(byte[] bytes) 248 { 249 if( bytes == null) 250 return null; 251 long a=((bytes[ 7] & 0xFFL) << 0) | 252 ((bytes[ 6] & 0xFFL) << 8) | 253 ((bytes[ 5] & 0xFFL) << 16) | 254 ((bytes[ 4] & 0xFFL) << 24) | 255 ((bytes[ 3] & 0xFFL) << 32) | 256 ((bytes[ 2] & 0xFFL) << 40) | 257 ((bytes[ 1] & 0xFFL) << 48) | 258 ((bytes[ 0] & 0xFFL) << 56); 259 260 double f=Double.longBitsToDouble(a); 261 Double d = new Double (f); 262 return d; 263 } 264 265 public static String getString(byte[] bytes) 266 { 267 if( bytes == null) 268 return null; 269 String ss1 = (new String ( bytes )).trim(); 270 return ss1; 271 } 272 273 public static Short getShort(byte[] bytes) 274 { 275 if( bytes == null) 276 return null; 277 short a= (short)((bytes[1] & 0xFF) << 0); 278 a |= (short)((bytes[0] & 0xFF) << 8); 279 Short aa = new Short (a); 280 return aa; 281 } 282 283 284 285 public static java.sql.Date getDate(byte[] bytes) 286 { 287 if(bytes == null) 288 return null; 289 long a = 0; 290 for(int i = 0 , j = 56 ; i < 8 ; i++ , j -= 8) 291 a += ((long)bytes[i] & 0xFF) << j; 292 return new com.daffodilwoods.daffodildb.utils.DBDate(a); 293 } 294 295 public static java.sql.Timestamp getTimestamp(byte[] bytes) 296 { 297 if(bytes == null) 298 return null; 299 300 byte day = bytes[0]; 301 byte month = bytes[1]; 302 303 byte b1[] = new byte[2]; 304 b1[0] = bytes[2]; 305 b1[1] = bytes[3]; 306 short year = getShort(b1).shortValue(); 307 int dd = (int)day; 308 int mm = (int)month; 309 int yr = (int)year; 310 311 byte hour = bytes[4]; 312 byte minutes = bytes[5]; 313 byte seconds = bytes[6]; 314 int hr = (int)hour; 315 int min = (int)minutes; 316 int sec = (int)seconds; 317 318 byte b2[] = new byte[4]; 319 b2[0] = bytes[7]; 320 b2[1] = bytes[8]; 321 b2[2] = bytes[9]; 322 b2[3] = bytes[10]; 323 int nanos = getInt(b2).intValue(); 324 java.sql.Timestamp timestamp = new java.sql.Timestamp (year , mm , dd,hr,min,seconds,nanos); 325 return timestamp; 326 } 327 328 public static java.sql.Time getTime(byte[] bytes) 329 { 330 if(bytes == null) 331 return null; 332 byte hour = bytes[0]; 333 byte minutes = bytes[1]; 334 byte seconds = bytes[2]; 335 int hr = (int)hour; 336 int min = (int)minutes; 337 int sec = (int)seconds; 338 java.sql.Time time = new java.sql.Time (hour , min , sec); 339 return time; 340 } 341 342 public static Boolean getBoolean(byte[] bytes) 343 { 344 if( bytes == null) 345 return null; 346 347 boolean a=false; 348 for(int i=0;i<1;i++) 349 a = (bytes[0]==1) ? true:false; 350 Boolean b = new Boolean (a); 351 return b; 352 } 353 354 355 public final static byte[] getBytes(Object value,int type,int size,boolean collator) throws DException 356 { 357 if(value == null) 358 return null; 359 switch (type ){ 360 case BINARY : 361 byte[] bytes = null; 362 if(value instanceof String ) 363 bytes = ((String )value).getBytes(); 364 else if(value instanceof byte[]) 365 bytes = (byte[])value; 366 else 367 throw new DException("DSE1105",new Object []{value}); 368 int length = bytes.length; 369 if( length > size ) 370 throw new SizeMisMatchException("DSE1166",new Object []{new Integer (length),new Integer (size)}); 371 if ( bytes.length == size ) 372 return bytes; 373 byte[] newBytes = new byte[length]; 374 System.arraycopy(bytes,0,newBytes,0,bytes.length); 375 return newBytes; 376 case VARBINARY : 377 if(value instanceof String ) 378 return ((String )value).getBytes(); 379 else if(value instanceof byte[]) 380 return (byte[])value; 381 else 382 throw new DException("DSE1105",new Object []{value}); 383 case CHARVARYING : 384 case CHARACTERVARYING : 385 case BITVARYING : 386 case VARCHAR : if( value instanceof java.lang.Character || 387 value instanceof java.lang.String ) 388 { 389 String temp = value.toString(); 390 return getBytes( temp , -1, collator ) ; 391 } 392 break; 393 case BIT : 394 case CHAR : 395 case CHARACTER : if( value instanceof java.lang.Character || 396 value instanceof java.lang.String ) 397 { 398 String temp = value.toString(); 399 return getBytes( temp , (temp.length() > size) ? -1 : size ,collator ); 400 } 401 break; 402 403 case BOOLEAN : if( value instanceof Boolean ) 404 return getBytes( (Boolean ) value ); 405 break; 406 407 case TIME : if( value instanceof java.sql.Time ) 408 return getBytes((java.sql.Time )value); 409 case TIMESTAMP : if( value instanceof java.sql.Timestamp ) 410 return getBytes((java.sql.Timestamp )value); 411 case DATE : if( value instanceof java.util.Date ) 412 return getBytes( (java.util.Date )value ); 413 break; 414 415 case FLOAT : 416 case DOUBLEPRECISION : 417 case DOUBLE : if( value instanceof Double ) 418 return getBytes( (Double )value ); 419 try{ 420 return getBytes(new Double (""+value)); 421 }catch(NumberFormatException nfe){ 422 throw new TypeMisMatchException( "DSE1167", new Object []{new Integer (type), (value == null ? null : value.getClass())} ); 423 } 424 425 case REAL : if( value instanceof Float ) 426 return getBytes( (Float )value ); 427 try{ 428 return getBytes(new Float (""+value)); 429 }catch(NumberFormatException nfe){ 430 throw new TypeMisMatchException( "DSE1167", new Object []{new Integer (type), (value == null ? null : value.getClass())} ); 431 } 432 433 case INT : 434 case INTEGER : if( value instanceof Integer ) 435 return getBytes((Integer )value); 436 if( value instanceof Short || value instanceof Long ) 437 return getBytes( new Integer ( value.hashCode() ) ); 438 if(value instanceof Float ) 439 return getBytes(new Integer (((Float )value).intValue())); 440 if(value instanceof Double ) 441 return getBytes(new Integer (((Double )value).intValue())); 442 break; 443 444 case LONG : 445 case BIGINT : 446 if( value instanceof Long || 447 value instanceof Integer || value instanceof Short || 448 value instanceof Float || value instanceof Double ) 449 return getBytes( getLongValue(value) ); 450 451 break; 452 453 case SMALLINT : 454 case SHORT : if( value instanceof Short ) 455 return getBytes( (Short )value ); 456 if( value instanceof Integer ) 457 return getBytes(new Short (((Integer )value).shortValue())); 458 if( value instanceof Long ) 459 return getBytes(new Short (((Long )value).shortValue())); 460 if(value instanceof Float ) 461 return getBytes(new Short (((Float )value).shortValue())); 462 if(value instanceof Double ) 463 return getBytes(new Short (((Double )value).shortValue())); 464 break; 465 466 case ARRAY : return getBytes( (Object []) value ); 467 468 case DEC : 469 case DECIMAL : 470 case NUMERIC : 471 case BIGDECIMAL : if( value instanceof java.math.BigDecimal ) 472 return getBytes((java.math.BigDecimal )value); 473 474 case BINARYLARGEOBJECT : 475 case LONGVARBINARY : 476 case BLOB : if( value instanceof byte[] ) 477 return (byte[])value; 478 if(value instanceof String ) 479 return ((String )value).getBytes(); 480 return getBytes( (java.sql.Blob )value ); 481 case TINYINT : 482 case BYTE : if( value instanceof Byte ) 483 return getBytes((Byte )value); 484 485 case CHARACTERLARGEOBJECT : 486 case LONGVARCHAR : 487 case CHARLARGEOBJECT : 488 case CLOB : if( value instanceof byte[] ) 489 return (byte[])value; 490 if(value instanceof String ) 491 return ((String )value).getBytes(); 492 return getBytes((java.sql.Clob )value ); 493 } 494 throw new TypeMisMatchException( "DSE1167", new Object []{new Integer (type), (value == null ? null : value.getClass())} ); 495 } 496 497 private static Long getLongValue( Object value ) throws DException 498 { 499 if( value == null ) 500 return null; if( value instanceof java.lang.Long ) 502 return ( Long ) value; 503 else if( value instanceof java.lang.Integer ) 504 return new Long ( ( (Integer ) value ).longValue() ); 505 else if( value instanceof java.lang.Float ) 506 return new Long ( ((Float )value).longValue() ); 507 else if( value instanceof java.lang.Double ) 508 return new Long ( ((Double ) value).longValue() ); 509 else if( value instanceof java.lang.Short ) 510 return new Long ( ((Short )value).longValue()); 511 else 512 throw new TypeMisMatchException( "DSE1167", new Object []{new Integer (LONG), (value == null ? null : value.getClass())} ); 513 } 514 515 public final static Object getObject(int type,byte[] bytes) throws DException { 516 if(bytes == null) 517 return null; 518 switch ( type ){ 519 case BIGINT : 520 case LONG : return getLong(bytes); 521 case INT : 522 case INTEGER : return getInt( bytes ); 523 524 case CHAR : 525 case CHARACTER : 526 case BIT : 527 return new String ( bytes ).trim(); 528 case VARCHAR : 529 case CHARACTERVARYING : 530 case CHARVARYING : 531 case BITVARYING : 532 return new String ( bytes ); 533 case BOOLEAN : return getBoolean( bytes ); 534 case DATE : return getDate( bytes ); 535 case DOUBLEPRECISION : 536 case FLOAT : 537 case DOUBLE : return getDouble( bytes ); 538 case REAL : return getFloat( bytes ); 539 540 case DEC : 541 case DECIMAL : 542 case NUMERIC : 543 case BIGDECIMAL : return getBigDecimal(bytes); 544 case TINYINT : 545 case BYTE : return getByte(bytes); 546 547 548 case TIME : return getTime(bytes); 549 case TIMESTAMP : return getTimestamp(bytes); 550 551 case MODULE : return getLong( bytes ); 552 553 case SMALLINT : 554 case SHORT : return getShort( bytes ); 555 case ARRAY : return ihfuBssbzPckfdu( bytes ); 556 557 case BINARY : 558 case VARBINARY : return bytes; 559 } 560 throw new IllegalColumnPropertyException("DSE1018",null); 561 } 562 563 private static int ihfuEbubcbtfUzqf(Object element) throws DException{ 564 if ( element == null ) 565 return -1; 566 if ( element instanceof java.lang.String ) 567 return CHARACTER; 568 if ( element instanceof java.lang.Integer ) 569 return INTEGER; 570 if ( element instanceof java.lang.Long ) 571 return LONG; 572 if ( element instanceof java.lang.Short ) 573 return SHORT; 574 if ( element instanceof java.lang.Boolean ) 575 return BOOLEAN; 576 if ( element instanceof java.lang.Float ) 577 return FLOAT; 578 if ( element instanceof java.lang.Double ) 579 return DOUBLE; 580 if ( element instanceof java.util.Date ) 581 return DATE; 582 if( element instanceof Byte ) 583 return BYTE; 584 if( element instanceof java.math.BigDecimal ) 585 return BIGDECIMAL; 586 if( element instanceof java.sql.Blob ) 587 return BLOB; 588 if( element instanceof java.sql.Clob ) 589 return CLOB; 590 if( element instanceof java.sql.Time ) 591 return TIME; 592 if(element instanceof java.sql.Timestamp ) 593 return TIMESTAMP; 594 throw new IllegalColumnPropertyException("DSE1018",null); 595 } 596 597 private static byte[] getBytes(Object [] array)throws DException{ 598 throw new DException("DSE492",null); 599 } 600 601 private static Object ihfuBssbzPckfdu(byte[] bytes)throws DException{ 602 if( bytes == null) 603 return null; 604 int pointer = 0; 605 java.util.ArrayList array = new java.util.ArrayList (10); 606 while( pointer < bytes.length ){ 607 int type = (int) bytes[pointer++]; 608 int objectSize = 0; 609 if( type == CHARACTER || type == VARCHAR ){ 610 byte[] sizeBytes = new byte[4]; 611 for(int i=0;i < 4; i++ ) 612 sizeBytes[i] = bytes[pointer++]; 613 614 objectSize = getInt(sizeBytes).intValue(); 615 } 616 else{ 617 objectSize = ihfuTjbf( type ); 618 } 619 620 byte[] objectBytes = new byte[objectSize]; 621 System.arraycopy(bytes,pointer,objectBytes,0,objectSize); 622 pointer+=objectSize; 623 624 array.add(getObject(type,objectBytes) ); 625 } 626 return array.toArray(new Object [array.size()]); 627 } 628 629 630 private static int ihfuTjbf(int type)throws DException{ 631 switch ( type ){ 632 case BOOLEAN : return BOOLEANSIZE; 633 case DATE : return DATESIZE; 634 case SUM : 635 case DOUBLEPRECISION : 636 case DOUBLE : return DOUBLESIZE; 637 case REAL : return REALSIZE; 638 case FLOAT : return FLOATSIZE; 639 case INT : 640 case INTEGER : return INTSIZE; 641 case BIGINT : 642 case LONG : 643 case MODULE : return LONGSIZE; 644 case SMALLINT : 645 case SHORT : return SHORTSIZE; 646 647 case TIME : return TIMESIZE; 648 case TIMESTAMP : return TIMESTAMPSIZE; 649 650 case BYTE : 651 case TINYINT : return BYTESIZE; 652 } 653 throw new IllegalColumnPropertyException("DSE1018",null); 654 } 655 656 public static boolean isConvertable(int columnType,int requiredType) throws DException{ 657 switch( requiredType ){ 658 case INTEGER : return columnType == SHORT || columnType == SMALLINT ; 659 case LONG : return columnType == SHORT || columnType == INTEGER || 660 columnType == SMALLINT || columnType == INT ; 661 case DOUBLE : return columnType == SHORT || columnType == INTEGER || 662 columnType == SMALLINT || columnType == INT || 663 columnType == LONG || columnType == BIGINT; 664 case FLOAT : return columnType == DOUBLE || columnType == DOUBLEPRECISION; 665 default : return false; 666 } 667 } 668 669 public static boolean isObjectType(int columnType) throws DException{ 670 return columnType == ARRAY || columnType == BOOLEAN || 671 columnType == TINYINT || 672 columnType == BYTE || columnType == BLOB || 673 columnType == BIGDECIMAL || columnType == CLOB || 674 columnType == CHARACTER || columnType == DATE || 675 columnType == DOUBLE || columnType == FLOAT || 676 columnType == BIGINT || 677 columnType == INTEGER || columnType == LONG || 678 columnType == MODULE || columnType == SHORT || 679 columnType == SUM || columnType == TIME || 680 columnType == TIMESTAMP || columnType == VARCHAR || 681 columnType == CHAR || columnType == CHARVARYING || 682 columnType == LONGVARCHAR || columnType == LONGVARBINARY || 683 columnType == CHARACTERVARYING || columnType == CHARACTERLARGEOBJECT || 684 columnType == CHARLARGEOBJECT || columnType == BINARYLARGEOBJECT || 685 columnType == NUMERIC || columnType == DECIMAL || 686 columnType == DEC || columnType == INT || 687 columnType == REAL || columnType == DOUBLEPRECISION || 688 columnType == SMALLINT || columnType == BIT || 689 columnType == BITVARYING ; 690 } 691 692 public final static long getLongValue(byte[] bytes,int position)throws DException{ 693 long a = ((bytes[position + 7] & 0xFFL) << 0) | 694 ((bytes[position + 6] & 0xFFL) << 8) | 695 ((bytes[position + 5] & 0xFFL) << 16) | 696 ((bytes[position + 4] & 0xFFL) << 24) | 697 ((bytes[position + 3] & 0xFFL) << 32) | 698 ((bytes[position + 2] & 0xFFL) << 40) | 699 ((bytes[position + 1] & 0xFFL) << 48)| 700 ((bytes[position + 0] & 0xFFL) << 56); 701 702 703 return a; 704 } 705 706 707 public final static long getLongValue(BufferRange bb,int position)throws DException{ 708 byte[] bytes = bb.getBytes() ; 709 long a = ((bytes[position + 7] & 0xFFL) << 0) | 710 ((bytes[position + 6] & 0xFFL) << 8) | 711 ((bytes[position + 5] & 0xFFL) << 16) | 712 ((bytes[position + 4] & 0xFFL) << 24) | 713 ((bytes[position + 3] & 0xFFL) << 32) | 714 ((bytes[position + 2] & 0xFFL) << 40) | 715 ((bytes[position + 1] & 0xFFL) << 48)| 716 ((bytes[position + 0] & 0xFFL) << 56); 717 718 719 return a; 720 } 721 722 723 724 public final static short getShortValue(byte[] bytes,int position){ 725 short a=0; 726 a = (short)(((short)bytes[position] & 0xFF) << 8); 727 a |= ((short)bytes[position+1] & 0xFF) << 0; 728 return a; 729 } 730 731 public final static short getShortValue(BufferRange bytes,int position)throws DException{ 732 short a=0; 733 a = (short)(( (short) bytes.getByte(position) & 0xFF) << 8); 734 a |= ( (short) bytes.getByte(position+1) & 0xFF) << 0; 735 return a; 736 } 737 738 public static byte[] getBytes(int a1){ 739 byte b[] = new byte[4]; 740 b[0] =(byte) ((a1 >>24) & 0xFF); 741 b[1] =(byte) ((a1 >>16) & 0xFF); 742 b[2] =(byte) ((a1 >> 8) & 0xFF); 743 b[3] =(byte) ((a1 >> 0) & 0xFF); 744 return b; 745 } 746 747 public static final byte[] getBytes(short al) { 748 byte b[]=new byte[2]; 749 b[0]=(byte)(( (al >>> 8)) & 0xFF); 750 b[1]=(byte)(( (al >>> 0)) & 0xFF); 751 return b; 752 } 753 754 755 public static Integer getInt(byte[] bytes) 756 { 757 if( bytes == null) 758 return null; 759 int a = ((bytes[ 3] & 0xFF) << 0) | 760 ((bytes[ 2] & 0xFF) << 8) | 761 ((bytes[ 1] & 0xFF) << 16) | 762 ((bytes[ 0] & 0xFF) << 24); 763 764 Integer aa = new Integer (a); 765 return aa; 766 } 767 768 769 public static int getIntValue(byte[] bytes,int position){ 770 int a=((bytes[position + 3] & 0xFF) << 0) + 771 ((bytes[position + 2] & 0xFF) << 8) + 772 ((bytes[position + 1] & 0xFF) << 16) + 773 ((bytes[position + 0] & 0xFF) << 24); 774 775 return a; 776 } 777 778 public static int getIntValue(BufferRange bytes,int off){ 779 byte[] b = bytes.getBytes(); 780 int a= ((b[off + 3] & 0xFF) << 0) | 781 ((b[off + 2] & 0xFF) << 8) | 782 ((b[off + 1] & 0xFF) << 16) | 783 ((b[off + 0] & 0xFF) << 24); 784 785 return a; 786 } 787 788 789 790 public static void putInt(byte[] b, int off, int val) { 791 b[off + 3] = (byte) (val >>> 0); 792 b[off + 2] = (byte) (val >>> 8); 793 b[off + 1] = (byte) (val >>> 16); 794 b[off + 0] = (byte) (val >>> 24); 795 } 796 797 798 } 799 | Popular Tags |