1 19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage; 20 21 import java.io.*; 22 import java.util.*; 23 import org.netbeans.mdr.util.Logger; 24 25 40 class ContinuationBtreeExtent extends ActiveBtreeExtent { 41 42 43 static final int CONTINUATION_FIXED_LENGTH = 12; 44 45 46 static final int MAX_CONTINUATION_DATA_LENGTH = 47 BtreeDataFile.MAX_BYTES_IN_EXTENT - CONTINUATION_FIXED_LENGTH; 48 49 54 ContinuationBtreeExtent(BtreeDataFile file, int chunkNum, short numChunks) { 55 super(file, chunkNum, numChunks); 56 dataStart = CONTINUATION_FIXED_LENGTH; 57 } 58 59 64 ContinuationBtreeExtent(DeletedBtreeExtent del, int length) { 65 super(del); 66 setMyDataLength(length); 67 dataStart = CONTINUATION_FIXED_LENGTH; 68 } 69 70 76 ContinuationBtreeExtent( 77 BtreeDataFile file, int chunkNum, short numChunks, int dLen) { 78 79 super(file, chunkNum, numChunks); 80 dataStart = CONTINUATION_FIXED_LENGTH; 81 setMyDataLength(dLen); 82 headerIsDirty = true; 83 } 84 85 90 void readHeaderFromPage(byte buffer[], IntHolder offset) { 91 dataLength = Converter.readInt(buffer, offset); 92 if (dataLength > getAvailableDataLength()) { 93 Logger.getDefault().log("Bad data length read: ----------------------"); 94 Logger.getDefault().log("chunk number: " + myChunkNum); 95 Logger.getDefault().log("dataLength: " + dataLength); 96 Logger.getDefault().log("available: " + getAvailableDataLength()); 97 } 98 } 99 100 104 protected void writeHeaderToPage(CachedPage page, int offset) { 105 Converter.writeInt(page.contents, offset, dataLength); 106 } 107 108 111 int getMyDataLength() { 112 return dataLength; 113 } 114 115 118 int getAvailableDataLength() { 119 return (chunks * BtreeDataFile.BTREE_CHUNK_SIZE) - 120 CONTINUATION_FIXED_LENGTH; 121 } 122 123 126 short getMagic() { 127 return CONTINUATION_MAGIC; 128 } 129 130 136 static int getNumChunks(int dataLength) { 137 int size = (dataLength + CONTINUATION_FIXED_LENGTH - 1) / 138 BtreeDataFile.BTREE_CHUNK_SIZE + 1; 139 return Math.min(size, BtreeDataFile.MAX_CHUNKS_IN_EXTENT); 140 } 141 142 145 int setMyDataLength(int length) { 146 int oldDatalength = dataLength; 147 dataLength = Math.min(length, getAvailableDataLength()); 148 if (oldDatalength != dataLength) { 149 headerIsDirty = true; 150 } 151 return dataLength; 152 } 153 154 157 boolean isMaximum() { 158 return dataLength == MAX_CONTINUATION_DATA_LENGTH; 159 } 160 161 164 byte getType() { 165 return IS_CONTINUATION; 166 } 167 168 171 String getTypeName() { 172 return CONTINUATION_NAME; 173 } 174 } 175 | Popular Tags |