1 19 20 package jxl.write.biff; 21 22 import jxl.biff.Type; 23 import jxl.biff.IntegerHelper; 24 import jxl.biff.WritableRecordData; 25 26 33 class ExtendedSSTRecord extends WritableRecordData 34 { 35 private static final int infoRecordSize = 8; 36 private int numberOfStrings; 37 private int[] absoluteStreamPositions; 38 private int[] relativeStreamPositions; 39 private int currentStringIndex = 0; 40 41 48 public ExtendedSSTRecord(int newNumberOfStrings) 49 { 50 super(Type.EXTSST); 51 numberOfStrings = newNumberOfStrings; 52 int numberOfBuckets = getNumberOfBuckets(); 53 absoluteStreamPositions = new int[numberOfBuckets]; 54 relativeStreamPositions = new int[numberOfBuckets]; 55 currentStringIndex = 0; 56 } 57 58 public int getNumberOfBuckets() 59 { 60 int numberOfStringsPerBucket = getNumberOfStringsPerBucket(); 61 return numberOfStringsPerBucket != 0 ? 62 (numberOfStrings + numberOfStringsPerBucket - 1) / 63 numberOfStringsPerBucket : 0; 64 } 65 66 public int getNumberOfStringsPerBucket() 67 { 68 final int bucketLimit = 128; 74 return (numberOfStrings + bucketLimit - 1) / bucketLimit; 75 } 76 77 public void addString(int absoluteStreamPosition, 78 int relativeStreamPosition) 79 { 80 absoluteStreamPositions[currentStringIndex] = 81 absoluteStreamPosition + relativeStreamPosition; 82 relativeStreamPositions[currentStringIndex] = relativeStreamPosition; 83 currentStringIndex++; 84 } 85 86 91 public byte[] getData() 92 { 93 int numberOfBuckets = getNumberOfBuckets(); 94 byte[] data = new byte[2 + (8 * numberOfBuckets)]; 95 IntegerHelper.getTwoBytes(getNumberOfStringsPerBucket(), data, 0); 97 98 for (int i = 0; i < numberOfBuckets; i++) 99 { 100 IntegerHelper.getFourBytes(absoluteStreamPositions[i], 102 data, 103 2 + (i * infoRecordSize)); 104 IntegerHelper.getTwoBytes(relativeStreamPositions[i], 106 data, 107 6 + (i * infoRecordSize)); 108 } 111 112 return data; 113 } 114 } 115 116 | Popular Tags |