Decodes four bytes from array source and writes the resulting bytes (up to three of them) to destination . The source and destination arrays can be manipulated anywhere along their length by specifying srcOffset and destOffset . This method does not check to
(
byte[] source, int srcOffset,
byte[] destination, int destOffset, int options )
| 1028 | * @since 1.3 |
| 1029 | */ |
| 1030 | private static int decode4to3( |
| 1031 | byte[] source, int srcOffset, |
| 1032 | byte[] destination, int destOffset, int options ) { |
| 1033 | |
| 1034 | // Lots of error checking and exception throwing |
| 1035 | if( source == null ){ |
| 1036 | throw new NullPointerException( "Source array was null." ); |
| 1037 | } // end if |
| 1038 | if( destination == null ){ |
| 1039 | throw new NullPointerException( "Destination array was null." ); |
| 1040 | } // end if |
| 1041 | if( srcOffset < 0 || srcOffset + 3 >= source.length ){ |
| 1042 | throw new IllegalArgumentException( String.format( |
| 1043 | "Source array with length %d cannot have offset of %d and still process four bytes.", source.length, srcOffset ) ); |
| 1044 | } // end if |
| 1045 | if( destOffset < 0 || destOffset +2 >= destination.length ){ |
| 1046 | throw new IllegalArgumentException( String.format( |
| 1047 | "Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset ) ); |
| 1048 | } // end if |
| 1049 | |
| 1050 | |
| 1051 | byte[] DECODABET = getDecodabet( options ); |
| 1052 | |
| 1053 | // Example: Dk== |
| 1054 | if( source[ srcOffset + 2] == EQUALS_SIGN ) { |
| 1055 | // Two ways to do the same thing. Don't know which way I like best. |
| 1056 | //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) |
| 1057 | // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); |
| 1058 | int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
| 1059 | | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); |
| 1060 | |
| 1061 | destination[ destOffset ] = (byte)( outBuff >>> 16 ); |
| 1062 | return 1; |
| 1063 | } |
| 1064 | |
| 1065 | // Example: DkL= |
| 1066 | else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) { |
| 1067 | // Two ways to do the same thing. Don't know which way I like best. |
| 1068 | //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) |
| 1069 | // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) |
| 1070 | // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); |
| 1071 | int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
| 1072 | | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) |
| 1073 | | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); |
| 1074 | |
| 1075 | destination[ destOffset ] = (byte)( outBuff >>> 16 ); |
| 1076 | destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); |
| 1077 | return 2; |
| 1078 | } |
| 1079 | |
| 1080 | // Example: DkLE |
| 1081 | else { |
| 1082 | // Two ways to do the same thing. Don't know which way I like best. |
| 1083 | //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) |
| 1084 | // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) |
| 1085 | // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) |
| 1086 | // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); |
| 1087 | int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) |
no test coverage detected