📄 storedfieldheader.java
字号:
/** read the field status @exception IOException Thrown by potential I/O errors while reading field header. */ public static final int readStatus(ObjectInput in) throws IOException { int status; if ((status = in.read()) >= 0) return status; else throw new EOFException(); } public static final int readStatus( byte[] page, int offset) { return(page[offset]); } /** * read the length of the field and hdr. * <p> * Optimized routine used to skip a field on a page. It returns the * total length of the field including the header portion. It operates * directly on the array and does no checking of it's own for limits on * the array length, so an array out of bounds exception may be thrown - * the routine is meant to be used to read a field from a page so this * should not happen. * <p> * * @return The length of the field on the page, including it's header. * * @param data the array where the field is. * @param offset the offset in the array where the field begin, ie. * the status byte is at data[offset]. * * @exception StandardException Standard exception policy. **/ public static final int readTotalFieldLength( byte[] data, int offset) throws IOException { if (SanityManager.DEBUG) { // this routine is meant to be called on the page, and FIXED fields // are only used in the log. if (isFixed(data[offset])) SanityManager.THROWASSERT("routine does not handle FIXED."); } if (((data[offset++]) & FIELD_NULL) != FIELD_NULL) { int value = data[offset]; if ((value & ~0x3f) == 0) { // length is stored in this byte, we also know that the 0x80 bit // was not set, so no need to mask off the sign extension from // the byte to int conversion. // account for 1 byte stored length of field + 1 for status. return(value + 2); } else if ((value & 0x80) == 0) { // length stored in 2 bytes. only use low 6 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((value & 0x40) == 0x40); } // top 8 bits of 2 byte length is stored in this byte, we also // know that the 0x80 bit was not set, so no need to mask off // the sign extension from the 1st byte to int conversion. Need // to mask the byte in data[offset + 1] to account for possible // sign extension. // add 3 to account for 2 byte length + 1 for status return((((value & 0x3f) << 8) | (data[offset + 1] & 0xff)) + 3); } else { // length stored in 4 bytes. only use low 7 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((value & 0x80) == 0x80); } // top 8 bits of 4 byte length is stored in this byte, we also // know that the 0x80 bit was set, so need to mask off the // sign extension from the 1st byte to int conversion. Need to // mask the bytes from the next 3 bytes data[offset + 1,2,3] to // account for possible sign extension. // add 5 to account for 4 byte length + 1 added to all returns return( (((value & 0x7f) << 24) | ((data[offset + 1] & 0xff) << 16) | ((data[offset + 2] & 0xff) << 8) | (data[offset + 3] & 0xff)) + 5); } } else { return(1); } } public static final int readFieldLengthAndSetStreamPosition( byte[] data, int offset, int status, int fieldDataSize, ArrayInputStream ais) throws IOException { if ((status & (FIELD_NULL | FIELD_FIXED)) == 0) { // usual case-not null, not fixed. Length stored as compressed int. // return(CompressedNumber.readInt(in)); int value = data[offset++]; if ((value & ~0x3f) == 0) { // usual case. // length is stored in this byte, we also know that the 0x80 bit // was not set, so no need to mask off the sign extension from // the byte to int conversion. // nothing to do, value already has int to return. } else if ((value & 0x80) == 0) { // length is stored in 2 bytes. use low 6 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((value & 0x40) == 0x40); } // top 8 bits of 2 byte length is stored in this byte, we also // know that the 0x80 bit was not set, so no need to mask off // the sign extension from the 1st byte to int conversion. // Need to mask the byte in data[offset + 1] to account for // possible sign extension. value = (((value & 0x3f) << 8) | (data[offset++] & 0xff)); } else { // length is stored in 4 bytes. only low 7 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((value & 0x80) == 0x80); } // top 8 bits of 4 byte length is stored in this byte, we also // know that the 0x80 bit was set, so need to mask off the // sign extension from the 1st byte to int conversion. Need to // mask the bytes from the next 3 bytes data[offset + 1,2,3] to // account for possible sign extension. // add 5 to account for 4 byte length + 1 added to all returns value = (((value & 0x7f) << 24) | ((data[offset++] & 0xff) << 16) | ((data[offset++] & 0xff) << 8) | (data[offset++] & 0xff)); } ais.setPosition(offset); return(value); } else if ((status & FIELD_NULL) != 0) { ais.setPosition(offset); return(0); } else { int fieldDataLength; // field data length is in a fixed size field, not compressed. if (fieldDataSize <= 2) { // read it in as short, because it was written out as short fieldDataLength = ((data[offset++] & 0xff) << 8) | (data[offset++] & 0xff); } else { // fieldDataLength = CompressedNumber.readInt(in); fieldDataLength = data[offset]; if ((fieldDataLength & ~0x3f) == 0) { // usual case. // length is stored in this byte, we also know that the 0x80 // bit was not set, so no need to mask off the sign // extension from the byte to int conversion. // nothing to do, fieldDataLength already has int to return. } else if ((fieldDataLength & 0x80) == 0) { // len is stored in 2 bytes. use low 6 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((fieldDataLength & 0x40) == 0x40); } // top 8 bits of 2 byte length is stored in this byte, we // also know that the 0x80 bit was not set, so no need to // mask off the sign extension from the 1st byte to int // conversion. Need to mask the byte in data[offset + 1] to // account for possible sign extension. fieldDataLength = (((fieldDataLength & 0x3f) << 8) | (data[offset + 1] & 0xff)); } else { // len is stored in 4 bytes. only low 7 bits from 1st byte. if (SanityManager.DEBUG) { SanityManager.ASSERT((fieldDataLength & 0x80) == 0x80); } // top 8 bits of 4 byte length is stored in this byte, we // also know that the 0x80 bit was set, so need to mask off // the sign extension from the 1st byte to int conversion. // Need to mask the bytes from the next 3 bytes // data[offset + 1,2,3] to account for possible sign // extension. fieldDataLength = (((fieldDataLength & 0x7f) << 24) | ((data[offset + 1] & 0xff) << 16) | ((data[offset + 2] & 0xff) << 8) | (data[offset + 3] & 0xff)); } offset = offset + fieldDataSize; } ais.setPosition(offset); return(fieldDataLength); } } /** read the field data length @exception IOException Thrown by potential I/O errors while reading field header. */ public static final int readFieldDataLength( ObjectInput in, int status, int fieldDataSize) throws IOException { if ((status & (FIELD_NULL | FIELD_FIXED)) == 0) { // usual case-not null, not fixed. Length stored as compressed int. return(CompressedNumber.readInt(in)); } else if ((status & FIELD_NULL) != 0) { // field is null or non-existent. return(0); } else { int fieldDataLength; // field data length is in a fixed size field, not compressed. if (fieldDataSize <= 2) { // read it in as short, because it was written out as short int ch1 = in.read(); int ch2 = in.read(); if ((ch1 | ch2) < 0) throw new EOFException(); fieldDataLength = ((ch1 << 8) + (ch2 << 0)); } else { fieldDataLength = CompressedNumber.readInt(in); int diffLen = fieldDataSize - CompressedNumber.sizeInt(fieldDataLength); if (diffLen != 0) in.skipBytes(diffLen); } return(fieldDataLength); } } public static String toDebugString(int status) { if (SanityManager.DEBUG) { StringBuffer str = new StringBuffer(100); if (isNull(status)) str.append("Null "); if (isOverflow(status)) str.append("Overflow "); if (isNonexistent(status)) str.append("Nonexistent "); if (isExtensible(status)) str.append("Extensible "); if (isTagged(status)) str.append("Tagged "); if (isFixed(status)) str.append("Fixed "); if (isNullable(status)) str.append("Nullable "); if (str.length() == 0) str.append("INITIAL "); return str.toString(); } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -