📄 compoundfile.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: CompoundFile.java
package jxl.write.biff;
import common.Assert;
import common.Logger;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import jxl.biff.BaseCompoundFile;
import jxl.biff.IntegerHelper;
import jxl.read.biff.BiffException;
// Referenced classes of package jxl.write.biff:
// CopyAdditionalPropertySetsException
final class CompoundFile extends BaseCompoundFile
{
private static final class ReadPropertyStorage
{
jxl.biff.BaseCompoundFile.PropertyStorage propertyStorage;
byte data[];
int number;
ReadPropertyStorage(jxl.biff.BaseCompoundFile.PropertyStorage ps, byte d[], int n)
{
propertyStorage = ps;
data = d;
number = n;
}
}
private static Logger logger;
private OutputStream out;
private byte excelData[];
private int size;
private int requiredSize;
private int numBigBlockDepotBlocks;
private int numSmallBlockDepotChainBlocks;
private int numSmallBlockDepotBlocks;
private int numExtensionBlocks;
private int extensionBlock;
private int excelDataBlocks;
private int rootStartBlock;
private int excelDataStartBlock;
private int bbdStartBlock;
private int sbdStartBlockChain;
private int sbdStartBlock;
private int additionalPropertyBlocks;
private int numSmallBlocks;
private int numPropertySets;
private int numRootEntryBlocks;
private ArrayList additionalPropertySets;
private HashMap standardPropertySets;
private int bbdPos;
private byte bigBlockDepot[];
static Class class$jxl$write$biff$CompoundFile; /* synthetic field */
public CompoundFile(byte data[], int l, OutputStream os, jxl.read.biff.CompoundFile rcf)
throws CopyAdditionalPropertySetsException, IOException
{
size = l;
excelData = data;
readAdditionalPropertySets(rcf);
numRootEntryBlocks = 1;
numPropertySets = 4 + (additionalPropertySets == null ? 0 : additionalPropertySets.size());
if(additionalPropertySets != null)
{
numSmallBlockDepotChainBlocks = getBigBlocksRequired(numSmallBlocks * 4);
numSmallBlockDepotBlocks = getBigBlocksRequired(numSmallBlocks * 64);
numRootEntryBlocks += getBigBlocksRequired(additionalPropertySets.size() * 128);
}
int blocks = getBigBlocksRequired(l);
if(l < 4096)
requiredSize = 4096;
else
requiredSize = blocks * 512;
out = os;
excelDataBlocks = requiredSize / 512;
numBigBlockDepotBlocks = 1;
int blockChainLength = 109;
int startTotalBlocks = excelDataBlocks + 8 + 8 + additionalPropertyBlocks + numSmallBlockDepotBlocks + numSmallBlockDepotChainBlocks + numRootEntryBlocks;
int totalBlocks = startTotalBlocks + numBigBlockDepotBlocks;
numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128D);
totalBlocks = startTotalBlocks + numBigBlockDepotBlocks;
numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128D);
totalBlocks = startTotalBlocks + numBigBlockDepotBlocks;
if(numBigBlockDepotBlocks > blockChainLength - 1)
{
extensionBlock = 0;
int bbdBlocksLeft = (numBigBlockDepotBlocks - blockChainLength) + 1;
numExtensionBlocks = (int)Math.ceil((double)bbdBlocksLeft / 127D);
totalBlocks = startTotalBlocks + numExtensionBlocks + numBigBlockDepotBlocks;
numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128D);
totalBlocks = startTotalBlocks + numExtensionBlocks + numBigBlockDepotBlocks;
} else
{
extensionBlock = -2;
numExtensionBlocks = 0;
}
excelDataStartBlock = numExtensionBlocks;
sbdStartBlock = -2;
if(additionalPropertySets != null && numSmallBlockDepotBlocks != 0)
sbdStartBlock = excelDataStartBlock + excelDataBlocks + additionalPropertyBlocks + 16;
sbdStartBlockChain = -2;
if(sbdStartBlock != -2)
sbdStartBlockChain = sbdStartBlock + numSmallBlockDepotBlocks;
if(sbdStartBlockChain != -2)
bbdStartBlock = sbdStartBlockChain + numSmallBlockDepotChainBlocks;
else
bbdStartBlock = excelDataStartBlock + excelDataBlocks + additionalPropertyBlocks + 16;
rootStartBlock = bbdStartBlock + numBigBlockDepotBlocks;
if(totalBlocks != rootStartBlock + numRootEntryBlocks)
{
logger.warn("Root start block and total blocks are inconsistent generated file may be corrupt");
logger.warn("RootStartBlock " + rootStartBlock + " totalBlocks " + totalBlocks);
}
}
private void readAdditionalPropertySets(jxl.read.biff.CompoundFile readCompoundFile)
throws CopyAdditionalPropertySetsException, IOException
{
if(readCompoundFile == null)
return;
additionalPropertySets = new ArrayList();
standardPropertySets = new HashMap();
int blocksRequired = 0;
int numPropertySets = readCompoundFile.getNumberOfPropertySets();
for(int i = 0; i < numPropertySets; i++)
{
jxl.biff.BaseCompoundFile.PropertyStorage ps = readCompoundFile.getPropertySet(i);
boolean standard = false;
if(ps.name.equalsIgnoreCase("Root Entry"))
{
standard = true;
ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i);
standardPropertySets.put("Root Entry", rps);
}
for(int j = 0; j < STANDARD_PROPERTY_SETS.length && !standard; j++)
{
if(!ps.name.equalsIgnoreCase(STANDARD_PROPERTY_SETS[j]))
continue;
jxl.biff.BaseCompoundFile.PropertyStorage ps2 = readCompoundFile.findPropertyStorage(ps.name);
Assert.verify(ps2 != null);
if(ps2 == ps)
{
standard = true;
ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i);
standardPropertySets.put(STANDARD_PROPERTY_SETS[j], rps);
}
}
if(standard)
continue;
try
{
byte data[] = null;
if(ps.size > 0)
data = readCompoundFile.getStream(i);
else
data = new byte[0];
ReadPropertyStorage rps = new ReadPropertyStorage(ps, data, i);
additionalPropertySets.add(rps);
if(data.length > 4096)
{
int blocks = getBigBlocksRequired(data.length);
blocksRequired += blocks;
} else
{
int blocks = getSmallBlocksRequired(data.length);
numSmallBlocks += blocks;
}
continue;
}
catch(BiffException e)
{
logger.error(e);
}
throw new CopyAdditionalPropertySetsException();
}
additionalPropertyBlocks = blocksRequired;
}
public void write()
throws IOException
{
writeHeader();
writeExcelData();
writeDocumentSummaryData();
writeSummaryData();
writeAdditionalPropertySets();
writeSmallBlockDepot();
writeSmallBlockDepotChain();
writeBigBlockDepot();
writePropertySets();
}
private void writeAdditionalPropertySets()
throws IOException
{
if(additionalPropertySets == null)
return;
Iterator i = additionalPropertySets.iterator();
do
{
if(!i.hasNext())
break;
ReadPropertyStorage rps = (ReadPropertyStorage)i.next();
byte data[] = rps.data;
if(data.length > 4096)
{
int numBlocks = getBigBlocksRequired(data.length);
int requiredSize = numBlocks * 512;
out.write(data, 0, data.length);
byte padding[] = new byte[requiredSize - data.length];
out.write(padding, 0, padding.length);
}
} while(true);
}
private void writeExcelData()
throws IOException
{
out.write(excelData, 0, size);
byte padding[] = new byte[requiredSize - size];
out.write(padding);
}
private void writeDocumentSummaryData()
throws IOException
{
byte padding[] = new byte[4096];
out.write(padding);
}
private void writeSummaryData()
throws IOException
{
byte padding[] = new byte[4096];
out.write(padding);
}
private void writeHeader()
throws IOException
{
byte headerBlock[] = new byte[512];
byte extensionBlockData[] = new byte[512 * numExtensionBlocks];
System.arraycopy(IDENTIFIER, 0, headerBlock, 0, IDENTIFIER.length);
headerBlock[24] = 62;
headerBlock[26] = 3;
headerBlock[28] = -2;
headerBlock[29] = -1;
headerBlock[30] = 9;
headerBlock[32] = 6;
headerBlock[57] = 16;
IntegerHelper.getFourBytes(numBigBlockDepotBlocks, headerBlock, 44);
IntegerHelper.getFourBytes(sbdStartBlockChain, headerBlock, 60);
IntegerHelper.getFourBytes(numSmallBlockDepotChainBlocks, headerBlock, 64);
IntegerHelper.getFourBytes(extensionBlock, headerBlock, 68);
IntegerHelper.getFourBytes(numExtensionBlocks, headerBlock, 72);
IntegerHelper.getFourBytes(rootStartBlock, headerBlock, 48);
int pos = 76;
int blocksToWrite = Math.min(numBigBlockDepotBlocks, 109);
int blocksWritten = 0;
for(int i = 0; i < blocksToWrite; i++)
{
IntegerHelper.getFourBytes(bbdStartBlock + i, headerBlock, pos);
pos += 4;
blocksWritten++;
}
for(int i = pos; i < 512; i++)
headerBlock[i] = -1;
out.write(headerBlock);
pos = 0;
for(int extBlock = 0; extBlock < numExtensionBlocks; extBlock++)
{
blocksToWrite = Math.min(numBigBlockDepotBlocks - blocksWritten, 127);
for(int j = 0; j < blocksToWrite; j++)
{
IntegerHelper.getFourBytes(bbdStartBlock + blocksWritten + j, extensionBlockData, pos);
pos += 4;
}
blocksWritten += blocksToWrite;
int nextBlock = blocksWritten != numBigBlockDepotBlocks ? extBlock + 1 : -2;
IntegerHelper.getFourBytes(nextBlock, extensionBlockData, pos);
pos += 4;
}
if(numExtensionBlocks > 0)
{
for(int i = pos; i < extensionBlockData.length; i++)
extensionBlockData[i] = -1;
out.write(extensionBlockData);
}
}
private void checkBbdPos()
throws IOException
{
if(bbdPos >= 512)
{
out.write(bigBlockDepot);
bigBlockDepot = new byte[512];
bbdPos = 0;
}
}
private void writeBlockChain(int startBlock, int numBlocks)
throws IOException
{
int blocksToWrite = numBlocks - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -