public static TextValue decode( long[] blocks, int offset, int length ) { long firstLong = blocks[offset]; if ( (firstLong & 0xFFFFFF0FFFFFFFFFL) == 0 ) { return Values.EMPTY_STRING; } // key(24b) + type(4) = 28 int encoding = (int) ((firstLong & 0x1F0000000L) >>> 28); // 5 bits of encoding int stringLength = (int) ((firstLong & 0x7E00000000L) >>> 33); // 6 bits of stringLength if ( encoding == LongerShortString.ENCODING_UTF8 ) { return decodeUTF8( blocks, offset, stringLength ); } if ( encoding == ENCODING_LATIN1 ) { return decodeLatin1( blocks, offset, stringLength ); } LongerShortString table = getEncodingTable( encoding ); assert table != null : "We only decode LongerShortStrings after we have consistently read the PropertyBlock " + "data from the page cache. Thus, we should never have an invalid encoding header here."; char[] result = new char[stringLength]; // encode shifts in the bytes with the first char at the MSB, therefore // we must "unshift" in the reverse order decode( result, blocks, offset, table ); // We know the char array is unshared, so use sharing constructor explicitly return Values.stringValue( UnsafeUtil.newSharedArrayString( result ) ); }
public static TextValue decode( long[] blocks, int offset, int length ) { long firstLong = blocks[offset]; if ( (firstLong & 0xFFFFFF0FFFFFFFFFL) == 0 ) { return Values.EMPTY_STRING; } // key(24b) + type(4) = 28 int encoding = (int) ((firstLong & 0x1F0000000L) >>> 28); // 5 bits of encoding int stringLength = (int) ((firstLong & 0x7E00000000L) >>> 33); // 6 bits of stringLength if ( encoding == LongerShortString.ENCODING_UTF8 ) { return decodeUTF8( blocks, offset, stringLength ); } if ( encoding == ENCODING_LATIN1 ) { return decodeLatin1( blocks, offset, stringLength ); } LongerShortString table = getEncodingTable( encoding ); assert table != null : "We only decode LongerShortStrings after we have consistently read the PropertyBlock " + "data from the page cache. Thus, we should never have an invalid encoding header here."; char[] result = new char[stringLength]; // encode shifts in the bytes with the first char at the MSB, therefore // we must "unshift" in the reverse order decode( result, blocks, offset, table ); // We know the char array is unshared, so use sharing constructor explicitly return Values.stringValue( UnsafeUtil.newSharedArrayString( result ) ); }