public static int calculateNumberOfBlocksUsed( long firstBlock ) { /* * [ lll,llle][eeee,tttt][kkkk,kkkk][kkkk,kkkk][kkkk,kkkk] */ int encoding = (int) ( ( firstBlock & 0x1F0000000L ) >> 28 ); int length = (int) ( ( firstBlock & 0x7E00000000L ) >> 33 ); if ( encoding == ENCODING_UTF8 || encoding == ENCODING_LATIN1 ) { return calculateNumberOfBlocksUsedForStep8(length); } LongerShortString encodingTable = getEncodingTable( encoding ); if ( encodingTable == null ) { // We probably did an inconsistent read of the first block return PropertyType.BLOCKS_USED_FOR_BAD_TYPE_OR_ENCODING; } return calculateNumberOfBlocksUsed( encodingTable, length ); }
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 int calculateNumberOfBlocksUsed( long firstBlock ) { /* * [ lll,llle][eeee,tttt][kkkk,kkkk][kkkk,kkkk][kkkk,kkkk] */ int encoding = (int) ( ( firstBlock & 0x1F0000000L ) >> 28 ); int length = (int) ( ( firstBlock & 0x7E00000000L ) >> 33 ); if ( encoding == ENCODING_UTF8 || encoding == ENCODING_LATIN1 ) { return calculateNumberOfBlocksUsedForStep8(length); } LongerShortString encodingTable = getEncodingTable( encoding ); if ( encodingTable == null ) { // We probably did an inconsistent read of the first block return PropertyType.BLOCKS_USED_FOR_BAD_TYPE_OR_ENCODING; } return calculateNumberOfBlocksUsed( encodingTable, length ); }
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 ) ); }