📄 sstrecord.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: SSTRecord.java
package jxl.read.biff;
import common.Assert;
import jxl.WorkbookSettings;
import jxl.biff.*;
// Referenced classes of package jxl.read.biff:
// Record
class SSTRecord extends RecordData
{
private static class BooleanHolder
{
public boolean value;
private BooleanHolder()
{
}
BooleanHolder(_cls1 x0)
{
this();
}
}
private static class ByteArrayHolder
{
public byte bytes[];
private ByteArrayHolder()
{
}
ByteArrayHolder(_cls1 x0)
{
this();
}
}
private int totalStrings;
private int uniqueStrings;
private String strings[];
private int continuationBreaks[];
public SSTRecord(Record t, Record continuations[], WorkbookSettings ws)
{
super(t);
int totalRecordLength = 0;
for(int i = 0; i < continuations.length; i++)
totalRecordLength += continuations[i].getLength();
totalRecordLength += getRecord().getLength();
byte data[] = new byte[totalRecordLength];
int pos = 0;
System.arraycopy(getRecord().getData(), 0, data, 0, getRecord().getLength());
pos += getRecord().getLength();
continuationBreaks = new int[continuations.length];
Record r = null;
for(int i = 0; i < continuations.length; i++)
{
r = continuations[i];
System.arraycopy(r.getData(), 0, data, pos, r.getLength());
continuationBreaks[i] = pos;
pos += r.getLength();
}
totalStrings = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);
uniqueStrings = IntegerHelper.getInt(data[4], data[5], data[6], data[7]);
strings = new String[uniqueStrings];
readStrings(data, 8, ws);
}
private void readStrings(byte data[], int offset, WorkbookSettings ws)
{
int pos = offset;
String s = null;
boolean asciiEncoding = false;
boolean richString = false;
boolean extendedString = false;
int formattingRuns = 0;
int extendedRunLength = 0;
for(int i = 0; i < uniqueStrings; i++)
{
int numChars = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
byte optionFlags = data[pos];
pos++;
extendedString = (optionFlags & 0x4) != 0;
richString = (optionFlags & 0x8) != 0;
if(richString)
{
formattingRuns = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
}
if(extendedString)
{
extendedRunLength = IntegerHelper.getInt(data[pos], data[pos + 1], data[pos + 2], data[pos + 3]);
pos += 4;
}
asciiEncoding = (optionFlags & 0x1) == 0;
ByteArrayHolder bah = new ByteArrayHolder(null);
BooleanHolder bh = new BooleanHolder(null);
bh.value = asciiEncoding;
pos += getChars(data, bah, pos, bh, numChars);
asciiEncoding = bh.value;
if(asciiEncoding)
s = StringHelper.getString(bah.bytes, numChars, 0, ws);
else
s = StringHelper.getUnicodeString(bah.bytes, numChars, 0);
strings[i] = s;
if(richString)
pos += 4 * formattingRuns;
if(extendedString)
pos += extendedRunLength;
if(pos > data.length)
Assert.verify(false, "pos exceeds record length");
}
}
private int getChars(byte source[], ByteArrayHolder bah, int pos, BooleanHolder ascii, int numChars)
{
int i = 0;
boolean spansBreak = false;
if(ascii.value)
bah.bytes = new byte[numChars];
else
bah.bytes = new byte[numChars * 2];
do
{
if(i >= continuationBreaks.length || spansBreak)
break;
spansBreak = pos <= continuationBreaks[i] && pos + bah.bytes.length > continuationBreaks[i];
if(!spansBreak)
i++;
} while(true);
if(!spansBreak)
{
System.arraycopy(source, pos, bah.bytes, 0, bah.bytes.length);
return bah.bytes.length;
}
int breakpos = continuationBreaks[i];
System.arraycopy(source, pos, bah.bytes, 0, breakpos - pos);
int bytesRead = breakpos - pos;
int charsRead;
if(ascii.value)
charsRead = bytesRead;
else
charsRead = bytesRead / 2;
bytesRead += getContinuedString(source, bah, bytesRead, i, ascii, numChars - charsRead);
return bytesRead;
}
private int getContinuedString(byte source[], ByteArrayHolder bah, int destPos, int contBreakIndex, BooleanHolder ascii, int charsLeft)
{
int breakpos = continuationBreaks[contBreakIndex];
int bytesRead = 0;
do
{
if(charsLeft <= 0)
break;
Assert.verify(contBreakIndex < continuationBreaks.length, "continuation break index");
if(ascii.value && source[breakpos] == 0)
{
int length = contBreakIndex != continuationBreaks.length - 1 ? Math.min(charsLeft, continuationBreaks[contBreakIndex + 1] - breakpos - 1) : charsLeft;
System.arraycopy(source, breakpos + 1, bah.bytes, destPos, length);
destPos += length;
bytesRead += length + 1;
charsLeft -= length;
ascii.value = true;
} else
if(!ascii.value && source[breakpos] != 0)
{
int length = contBreakIndex != continuationBreaks.length - 1 ? Math.min(charsLeft * 2, continuationBreaks[contBreakIndex + 1] - breakpos - 1) : charsLeft * 2;
System.arraycopy(source, breakpos + 1, bah.bytes, destPos, length);
destPos += length;
bytesRead += length + 1;
charsLeft -= length / 2;
ascii.value = false;
} else
if(!ascii.value && source[breakpos] == 0)
{
int chars = contBreakIndex != continuationBreaks.length - 1 ? Math.min(charsLeft, continuationBreaks[contBreakIndex + 1] - breakpos - 1) : charsLeft;
for(int j = 0; j < chars; j++)
{
bah.bytes[destPos] = source[breakpos + j + 1];
destPos += 2;
}
bytesRead += chars + 1;
charsLeft -= chars;
ascii.value = false;
} else
{
byte oldBytes[] = bah.bytes;
bah.bytes = new byte[destPos * 2 + charsLeft * 2];
for(int j = 0; j < destPos; j++)
bah.bytes[j * 2] = oldBytes[j];
destPos *= 2;
int length = contBreakIndex != continuationBreaks.length - 1 ? Math.min(charsLeft * 2, continuationBreaks[contBreakIndex + 1] - breakpos - 1) : charsLeft * 2;
System.arraycopy(source, breakpos + 1, bah.bytes, destPos, length);
destPos += length;
bytesRead += length + 1;
charsLeft -= length / 2;
ascii.value = false;
}
if(++contBreakIndex < continuationBreaks.length)
breakpos = continuationBreaks[contBreakIndex];
} while(true);
return bytesRead;
}
public String getString(int index)
{
Assert.verify(index < uniqueStrings);
return strings[index];
}
// Unreferenced inner classes:
/* anonymous class */
static class _cls1
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -