📄 compoundfile.java
字号:
int blockNumber = startBlock + 1;
while(blocksToWrite > 0)
{
int bbdBlocks = Math.min(blocksToWrite, (512 - bbdPos) / 4);
for(int i = 0; i < bbdBlocks; i++)
{
IntegerHelper.getFourBytes(blockNumber, bigBlockDepot, bbdPos);
bbdPos += 4;
blockNumber++;
}
blocksToWrite -= bbdBlocks;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
}
private void writeAdditionalPropertySetBlockChains()
throws IOException
{
if(additionalPropertySets == null)
return;
int blockNumber = excelDataStartBlock + excelDataBlocks + 16;
Iterator i = additionalPropertySets.iterator();
do
{
if(!i.hasNext())
break;
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
if(rps.data.length > 4096)
{
int numBlocks = getBigBlocksRequired(rps.data.length);
writeBlockChain(blockNumber, numBlocks);
blockNumber += numBlocks;
}
} while(true);
}
private void writeSmallBlockDepotChain()
throws IOException
{
if(sbdStartBlockChain == -2)
return;
byte smallBlockDepotChain[] = new byte[numSmallBlockDepotChainBlocks * 512];
int pos = 0;
int sbdBlockNumber = 1;
Iterator i = additionalPropertySets.iterator();
do
{
if(!i.hasNext())
break;
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
if(rps.data.length <= 4096 && rps.data.length != 0)
{
int numSmallBlocks = getSmallBlocksRequired(rps.data.length);
for(int j = 0; j < numSmallBlocks - 1; j++)
{
IntegerHelper.getFourBytes(sbdBlockNumber, smallBlockDepotChain, pos);
pos += 4;
sbdBlockNumber++;
}
IntegerHelper.getFourBytes(-2, smallBlockDepotChain, pos);
pos += 4;
sbdBlockNumber++;
}
} while(true);
out.write(smallBlockDepotChain);
}
private void writeSmallBlockDepot()
throws IOException
{
if(additionalPropertySets == null)
return;
byte smallBlockDepot[] = new byte[numSmallBlockDepotBlocks * 512];
int pos = 0;
Iterator i = additionalPropertySets.iterator();
do
{
if(!i.hasNext())
break;
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
if(rps.data.length <= 4096)
{
int smallBlocks = getSmallBlocksRequired(rps.data.length);
int length = smallBlocks * 64;
System.arraycopy(rps.data, 0, smallBlockDepot, pos, rps.data.length);
pos += length;
}
} while(true);
out.write(smallBlockDepot);
}
private void writeBigBlockDepot()
throws IOException
{
bigBlockDepot = new byte[512];
bbdPos = 0;
for(int i = 0; i < numExtensionBlocks; i++)
{
IntegerHelper.getFourBytes(-3, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
}
writeBlockChain(excelDataStartBlock, excelDataBlocks);
int summaryInfoBlock = excelDataStartBlock + excelDataBlocks + additionalPropertyBlocks;
for(int i = summaryInfoBlock; i < summaryInfoBlock + 7; i++)
{
IntegerHelper.getFourBytes(i + 1, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
for(int i = summaryInfoBlock + 8; i < summaryInfoBlock + 15; i++)
{
IntegerHelper.getFourBytes(i + 1, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
writeAdditionalPropertySetBlockChains();
if(sbdStartBlock != -2)
{
writeBlockChain(sbdStartBlock, numSmallBlockDepotBlocks);
writeBlockChain(sbdStartBlockChain, numSmallBlockDepotChainBlocks);
}
for(int i = 0; i < numBigBlockDepotBlocks; i++)
{
IntegerHelper.getFourBytes(-3, bigBlockDepot, bbdPos);
bbdPos += 4;
checkBbdPos();
}
writeBlockChain(rootStartBlock, numRootEntryBlocks);
if(bbdPos != 0)
{
for(int i = bbdPos; i < 512; i++)
bigBlockDepot[i] = -1;
out.write(bigBlockDepot);
}
}
private int getBigBlocksRequired(int length)
{
int blocks = length / 512;
return length % 512 <= 0 ? blocks : blocks + 1;
}
private int getSmallBlocksRequired(int length)
{
int blocks = length / 64;
return length % 64 <= 0 ? blocks : blocks + 1;
}
private void writePropertySets()
throws IOException
{
byte propertySetStorage[] = new byte[512 * numRootEntryBlocks];
int pos = 0;
int mappings[] = null;
if(additionalPropertySets != null)
{
mappings = new int[numPropertySets];
for(int i = 0; i < STANDARD_PROPERTY_SETS.length; i++)
{
ReadPropertyStorage rps = (ReadPropertyStorage)standardPropertySets.get(STANDARD_PROPERTY_SETS[i]);
if(rps != null)
mappings[rps.number] = i;
else
logger.warn("Standard property set " + STANDARD_PROPERTY_SETS[i] + " not present in source file");
}
int newMapping = STANDARD_PROPERTY_SETS.length;
for(Iterator i = additionalPropertySets.iterator(); i.hasNext();)
{
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
mappings[rps.number] = newMapping;
newMapping++;
}
}
int child = 0;
int previous = 0;
int next = 0;
int size = 0;
if(additionalPropertySets != null)
{
size += getBigBlocksRequired(requiredSize) * 512;
size += getBigBlocksRequired(4096) * 512;
size += getBigBlocksRequired(4096) * 512;
Iterator i = additionalPropertySets.iterator();
do
{
if(!i.hasNext())
break;
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
if(rps.propertyStorage.type != 1)
if(rps.propertyStorage.size >= 4096)
size += getBigBlocksRequired(rps.propertyStorage.size) * 512;
else
size += getSmallBlocksRequired(rps.propertyStorage.size) * 64;
} while(true);
}
jxl.biff.BaseCompoundFile.PropertyStorage ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, "Root Entry");
ps.setType(5);
ps.setStartBlock(sbdStartBlock);
ps.setSize(size);
ps.setPrevious(-1);
ps.setNext(-1);
ps.setColour(0);
child = 1;
if(additionalPropertySets != null)
{
ReadPropertyStorage rps = (ReadPropertyStorage)standardPropertySets.get("Root Entry");
child = mappings[rps.propertyStorage.child];
}
ps.setChild(child);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, "Workbook");
ps.setType(2);
ps.setStartBlock(excelDataStartBlock);
ps.setSize(requiredSize);
previous = 3;
next = -1;
if(additionalPropertySets != null)
{
ReadPropertyStorage rps = (ReadPropertyStorage)standardPropertySets.get("Workbook");
previous = rps.propertyStorage.previous == -1 ? -1 : mappings[rps.propertyStorage.previous];
next = rps.propertyStorage.next == -1 ? -1 : mappings[rps.propertyStorage.next];
}
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, "\005SummaryInformation");
ps.setType(2);
ps.setStartBlock(excelDataStartBlock + excelDataBlocks);
ps.setSize(4096);
previous = 1;
next = 3;
if(additionalPropertySets != null)
{
ReadPropertyStorage rps = (ReadPropertyStorage)standardPropertySets.get("\005SummaryInformation");
if(rps != null)
{
previous = rps.propertyStorage.previous == -1 ? -1 : mappings[rps.propertyStorage.previous];
next = rps.propertyStorage.next == -1 ? -1 : mappings[rps.propertyStorage.next];
}
}
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, "\005DocumentSummaryInformation");
ps.setType(2);
ps.setStartBlock(excelDataStartBlock + excelDataBlocks + 8);
ps.setSize(4096);
ps.setPrevious(-1);
ps.setNext(-1);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
if(additionalPropertySets == null)
{
out.write(propertySetStorage);
return;
}
int bigBlock = excelDataStartBlock + excelDataBlocks + 16;
int smallBlock = 0;
for(Iterator i = additionalPropertySets.iterator(); i.hasNext();)
{
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
int block = rps.data.length <= 4096 ? smallBlock : bigBlock;
ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, rps.propertyStorage.name);
ps.setType(rps.propertyStorage.type);
ps.setStartBlock(block);
ps.setSize(rps.propertyStorage.size);
previous = rps.propertyStorage.previous == -1 ? -1 : mappings[rps.propertyStorage.previous];
next = rps.propertyStorage.next == -1 ? -1 : mappings[rps.propertyStorage.next];
child = rps.propertyStorage.child == -1 ? -1 : mappings[rps.propertyStorage.child];
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(child);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
if(rps.data.length > 4096)
bigBlock += getBigBlocksRequired(rps.data.length);
else
smallBlock += getSmallBlocksRequired(rps.data.length);
}
out.write(propertySetStorage);
}
static Class class$(String x0)
{
return Class.forName(x0);
ClassNotFoundException x1;
x1;
throw new NoClassDefFoundError(x1.getMessage());
}
static
{
logger = Logger.getLogger(class$jxl$write$biff$CompoundFile != null ? class$jxl$write$biff$CompoundFile : (class$jxl$write$biff$CompoundFile = class$("jxl.write.biff.CompoundFile")));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -