⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compoundfile.java

📁 实现JAVA界面的代码GWT
💻 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.read.biff;

import common.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.WorkbookSettings;
import jxl.biff.BaseCompoundFile;
import jxl.biff.IntegerHelper;

// Referenced classes of package jxl.read.biff:
//            BiffException

public final class CompoundFile extends BaseCompoundFile
{

    private static Logger logger;
    private byte data[];
    private int numBigBlockDepotBlocks;
    private int sbdStartBlock;
    private int rootStartBlock;
    private int extensionBlock;
    private int numExtensionBlocks;
    private byte rootEntry[];
    private int bigBlockChain[];
    private int smallBlockChain[];
    private int bigBlockDepotBlocks[];
    private ArrayList propertySets;
    private WorkbookSettings settings;
    private jxl.biff.BaseCompoundFile.PropertyStorage rootEntryPropertyStorage;
    static Class class$jxl$read$biff$CompoundFile; /* synthetic field */

    public CompoundFile(byte d[], WorkbookSettings ws)
        throws BiffException
    {
        data = d;
        settings = ws;
        for(int i = 0; i < IDENTIFIER.length; i++)
            if(data[i] != IDENTIFIER[i])
                throw new BiffException(BiffException.unrecognizedOLEFile);

        propertySets = new ArrayList();
        numBigBlockDepotBlocks = IntegerHelper.getInt(data[44], data[45], data[46], data[47]);
        sbdStartBlock = IntegerHelper.getInt(data[60], data[61], data[62], data[63]);
        rootStartBlock = IntegerHelper.getInt(data[48], data[49], data[50], data[51]);
        extensionBlock = IntegerHelper.getInt(data[68], data[69], data[70], data[71]);
        numExtensionBlocks = IntegerHelper.getInt(data[72], data[73], data[74], data[75]);
        bigBlockDepotBlocks = new int[numBigBlockDepotBlocks];
        int pos = 76;
        int bbdBlocks = numBigBlockDepotBlocks;
        if(numExtensionBlocks != 0)
            bbdBlocks = 109;
        for(int i = 0; i < bbdBlocks; i++)
        {
            bigBlockDepotBlocks[i] = IntegerHelper.getInt(d[pos], d[pos + 1], d[pos + 2], d[pos + 3]);
            pos += 4;
        }

        for(int j = 0; j < numExtensionBlocks; j++)
        {
            pos = (extensionBlock + 1) * 512;
            int blocksToRead = Math.min(numBigBlockDepotBlocks - bbdBlocks, 127);
            for(int i = bbdBlocks; i < bbdBlocks + blocksToRead; i++)
            {
                bigBlockDepotBlocks[i] = IntegerHelper.getInt(d[pos], d[pos + 1], d[pos + 2], d[pos + 3]);
                pos += 4;
            }

            bbdBlocks += blocksToRead;
            if(bbdBlocks < numBigBlockDepotBlocks)
                extensionBlock = IntegerHelper.getInt(d[pos], d[pos + 1], d[pos + 2], d[pos + 3]);
        }

        readBigBlockDepot();
        readSmallBlockDepot();
        rootEntry = readData(rootStartBlock);
        readPropertySets();
    }

    private void readBigBlockDepot()
    {
        int pos = 0;
        int index = 0;
        bigBlockChain = new int[(numBigBlockDepotBlocks * 512) / 4];
        for(int i = 0; i < numBigBlockDepotBlocks; i++)
        {
            pos = (bigBlockDepotBlocks[i] + 1) * 512;
            for(int j = 0; j < 128; j++)
            {
                bigBlockChain[index] = IntegerHelper.getInt(data[pos], data[pos + 1], data[pos + 2], data[pos + 3]);
                pos += 4;
                index++;
            }

        }

    }

    private void readSmallBlockDepot()
    {
        int pos = 0;
        int index = 0;
        int sbdBlock = sbdStartBlock;
        smallBlockChain = new int[0];
        if(sbdBlock == -1)
        {
            logger.warn("invalid small block depot number");
            return;
        }
        for(; sbdBlock != -2; sbdBlock = bigBlockChain[sbdBlock])
        {
            int oldChain[] = smallBlockChain;
            smallBlockChain = new int[smallBlockChain.length + 128];
            System.arraycopy(oldChain, 0, smallBlockChain, 0, oldChain.length);
            pos = (sbdBlock + 1) * 512;
            for(int j = 0; j < 128; j++)
            {
                smallBlockChain[index] = IntegerHelper.getInt(data[pos], data[pos + 1], data[pos + 2], data[pos + 3]);
                pos += 4;
                index++;
            }

        }

    }

    private void readPropertySets()
    {
        int offset = 0;
        byte d[] = null;
        for(; offset < rootEntry.length; offset += 128)
        {
            d = new byte[128];
            System.arraycopy(rootEntry, offset, d, 0, d.length);
            jxl.biff.BaseCompoundFile.PropertyStorage ps = new jxl.biff.BaseCompoundFile.PropertyStorage(this, d);
            if(ps.name == null || ps.name.length() == 0)
                if(ps.type == 5)
                {
                    ps.name = "Root Entry";
                    logger.warn("Property storage name for " + ps.type + " is empty - setting to " + "Root Entry");
                } else
                if(ps.size != 0)
                    logger.warn("Property storage type " + ps.type + " is non-empty and has no associated name");
            propertySets.add(ps);
            if(ps.name.equalsIgnoreCase("Root Entry"))
                rootEntryPropertyStorage = ps;
        }

        if(rootEntryPropertyStorage == null)
            rootEntryPropertyStorage = (jxl.biff.BaseCompoundFile.PropertyStorage)propertySets.get(0);
    }

    public byte[] getStream(String streamName)
        throws BiffException
    {
        jxl.biff.BaseCompoundFile.PropertyStorage ps = findPropertyStorage(streamName, rootEntryPropertyStorage);
        if(ps == null)
            ps = getPropertyStorage(streamName);
        if(ps.size >= 4096 || streamName.equalsIgnoreCase("Root Entry"))
            return getBigBlockStream(ps);
        else
            return getSmallBlockStream(ps);
    }

    public byte[] getStream(int psIndex)
        throws BiffException
    {
        jxl.biff.BaseCompoundFile.PropertyStorage ps = getPropertyStorage(psIndex);
        if(ps.size >= 4096 || ps.name.equalsIgnoreCase("Root Entry"))
            return getBigBlockStream(ps);
        else
            return getSmallBlockStream(ps);
    }

    public jxl.biff.BaseCompoundFile.PropertyStorage findPropertyStorage(String name)
    {
        return findPropertyStorage(name, rootEntryPropertyStorage);
    }

    private jxl.biff.BaseCompoundFile.PropertyStorage findPropertyStorage(String name, jxl.biff.BaseCompoundFile.PropertyStorage base)
    {
        if(base.child == -1)
            return null;
        jxl.biff.BaseCompoundFile.PropertyStorage child = getPropertyStorage(base.child);
        if(child.name.equalsIgnoreCase(name))
            return child;
        for(jxl.biff.BaseCompoundFile.PropertyStorage prev = child; prev.previous != -1;)
        {
            prev = getPropertyStorage(prev.previous);
            if(prev.name.equalsIgnoreCase(name))
                return prev;
        }

        for(jxl.biff.BaseCompoundFile.PropertyStorage next = child; next.next != -1;)
        {
            next = getPropertyStorage(next.next);
            if(next.name.equalsIgnoreCase(name))
                return next;
        }

        return findPropertyStorage(name, child);
    }

    private jxl.biff.BaseCompoundFile.PropertyStorage getPropertyStorage(String name)
        throws BiffException
    {
        Iterator i = propertySets.iterator();
        boolean found = false;
        boolean multiple = false;
        jxl.biff.BaseCompoundFile.PropertyStorage ps = null;
        do
        {
            if(!i.hasNext())
                break;
            jxl.biff.BaseCompoundFile.PropertyStorage ps2 = (jxl.biff.BaseCompoundFile.PropertyStorage)i.next();
            if(ps2.name.equalsIgnoreCase(name))
            {
                multiple = found;
                found = true;
                ps = ps2;
            }
        } while(true);
        if(multiple)
            logger.warn("found multiple copies of property set " + name);
        if(!found)
            throw new BiffException(BiffException.streamNotFound);
        else
            return ps;
    }

    private jxl.biff.BaseCompoundFile.PropertyStorage getPropertyStorage(int index)
    {
        return (jxl.biff.BaseCompoundFile.PropertyStorage)propertySets.get(index);
    }

    private byte[] getBigBlockStream(jxl.biff.BaseCompoundFile.PropertyStorage ps)
    {
        int numBlocks = ps.size / 512;
        if(ps.size % 512 != 0)
            numBlocks++;
        byte streamData[] = new byte[numBlocks * 512];
        int block = ps.startBlock;
        int count = 0;
        int pos = 0;
        for(; block != -2 && count < numBlocks; block = bigBlockChain[block])
        {
            pos = (block + 1) * 512;
            System.arraycopy(data, pos, streamData, count * 512, 512);
            count++;
        }

        if(block != -2 && count == numBlocks)
            logger.warn("Property storage size inconsistent with block chain.");
        return streamData;
    }

    private byte[] getSmallBlockStream(jxl.biff.BaseCompoundFile.PropertyStorage ps)
        throws BiffException
    {
        byte rootdata[] = readData(rootEntryPropertyStorage.startBlock);
        byte sbdata[] = new byte[0];
        int block = ps.startBlock;
        int pos = 0;
        do
        {
            if(block == -2)
                break;
            byte olddata[] = sbdata;
            sbdata = new byte[olddata.length + 64];
            System.arraycopy(olddata, 0, sbdata, 0, olddata.length);
            pos = block * 64;
            System.arraycopy(rootdata, pos, sbdata, olddata.length, 64);
            block = smallBlockChain[block];
            if(block == -1)
            {
                logger.warn("Incorrect terminator for small block stream " + ps.name);
                block = -2;
            }
        } while(true);
        return sbdata;
    }

    private byte[] readData(int bl)
        throws BiffException
    {
        int block = bl;
        int pos = 0;
        byte entry[] = new byte[0];
        for(; block != -2; block = bigBlockChain[block])
        {
            byte oldEntry[] = entry;
            entry = new byte[oldEntry.length + 512];
            System.arraycopy(oldEntry, 0, entry, 0, oldEntry.length);
            pos = (block + 1) * 512;
            System.arraycopy(data, pos, entry, oldEntry.length, 512);
            if(bigBlockChain[block] == block)
                throw new BiffException(BiffException.corruptFileFormat);
        }

        return entry;
    }

    public int getNumberOfPropertySets()
    {
        return propertySets.size();
    }

    public jxl.biff.BaseCompoundFile.PropertyStorage getPropertySet(int index)
    {
        return getPropertyStorage(index);
    }

    static Class class$(String x0)
    {
        return Class.forName(x0);
        ClassNotFoundException x1;
        x1;
        throw new NoClassDefFoundError(x1.getMessage());
    }

    static 
    {
        logger = Logger.getLogger(class$jxl$read$biff$CompoundFile != null ? class$jxl$read$biff$CompoundFile : (class$jxl$read$biff$CompoundFile = class$("jxl.read.biff.CompoundFile")));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -