📄 sharedstrings.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: SharedStrings.java
package jxl.write.biff;
import java.io.IOException;
import java.util.*;
// Referenced classes of package jxl.write.biff:
// SSTRecord, ExtendedSSTRecord, SSTContinueRecord, File
class SharedStrings
{
private HashMap strings;
private ArrayList stringList;
private int totalOccurrences;
public SharedStrings()
{
strings = new HashMap(100);
stringList = new ArrayList(100);
totalOccurrences = 0;
}
public int getIndex(String s)
{
Integer i = (Integer)strings.get(s);
if(i == null)
{
i = new Integer(strings.size());
strings.put(s, i);
stringList.add(s);
}
totalOccurrences++;
return i.intValue();
}
public String get(int i)
{
return (String)stringList.get(i);
}
public void write(File outputFile)
throws IOException
{
int charsLeft = 0;
String curString = null;
SSTRecord sst = new SSTRecord(totalOccurrences, stringList.size());
ExtendedSSTRecord extsst = new ExtendedSSTRecord(stringList.size());
int bucketSize = extsst.getNumberOfStringsPerBucket();
Iterator i = stringList.iterator();
int stringIndex;
for(stringIndex = 0; i.hasNext() && charsLeft == 0; stringIndex++)
{
curString = (String)i.next();
int relativePosition = sst.getOffset() + 4;
charsLeft = sst.add(curString);
if(stringIndex % bucketSize == 0)
extsst.addString(outputFile.getPos(), relativePosition);
}
outputFile.write(sst);
if(charsLeft != 0 || i.hasNext())
{
SSTContinueRecord cont = createContinueRecord(curString, charsLeft, outputFile);
do
{
if(!i.hasNext())
break;
curString = (String)i.next();
int relativePosition = cont.getOffset() + 4;
charsLeft = cont.add(curString);
if(stringIndex % bucketSize == 0)
extsst.addString(outputFile.getPos(), relativePosition);
stringIndex++;
if(charsLeft != 0)
{
outputFile.write(cont);
cont = createContinueRecord(curString, charsLeft, outputFile);
}
} while(true);
outputFile.write(cont);
}
outputFile.write(extsst);
}
private SSTContinueRecord createContinueRecord(String curString, int charsLeft, File outputFile)
throws IOException
{
SSTContinueRecord cont = null;
do
{
if(charsLeft == 0)
break;
cont = new SSTContinueRecord();
if(charsLeft == curString.length() || curString.length() == 0)
charsLeft = cont.setFirstString(curString, true);
else
charsLeft = cont.setFirstString(curString.substring(curString.length() - charsLeft), false);
if(charsLeft != 0)
{
outputFile.write(cont);
cont = new SSTContinueRecord();
}
} while(true);
return cont;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -