Package org.apache.poi.hwpf.model
Class TextPieceTable
- java.lang.Object
-
- org.apache.poi.hwpf.model.TextPieceTable
-
- All Implemented Interfaces:
CharIndexTranslator
- Direct Known Subclasses:
OldTextPieceTable
@Internal public class TextPieceTable extends Object implements CharIndexTranslator
The piece table for matching up character positions to bits of text. This mostly works in bytes, but the TextPieces themselves work in characters. This does the icky conversion.
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<TextPiece>_textPiecesprotected ArrayList<TextPiece>_textPiecesFCOrder
-
Constructor Summary
Constructors Constructor Description TextPieceTable()TextPieceTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(TextPiece piece)intadjustForInsert(int listIndex, int length)Adjust all the text piece after inserting some text into one of thembooleanequals(Object o)intgetByteIndex(int charPos)Calculates the byte index of the given char index.intgetCharIndex(int bytePos)Deprecated.intgetCharIndex(int startBytePos, int startCP)Deprecated.int[][]getCharIndexRanges(int startBytePosInclusive, int endBytePosExclusive)Finds character ranges that includes specified byte range.intgetCpMin()protected intgetEncodingMultiplier(TextPiece textPiece)static intgetMaxRecordLength()StringBuildergetText()List<TextPiece>getTextPieces()inthashCode()booleanisIndexInTable(int bytePos)Check if index is in tableintlookIndexBackward(int startBytePos)Return last index <= bytePos that is in tableintlookIndexForward(int startBytePos)Return first index >= bytePos that is in tableprotected TextPiecenewTextPiece(int nodeStartChars, int nodeEndChars, byte[] buf, PieceDescriptor pd)static voidsetMaxRecordLength(int length)byte[]writeTo(ByteArrayOutputStream docStream)
-
-
-
Method Detail
-
setMaxRecordLength
public static void setMaxRecordLength(int length)
- Parameters:
length- the max record length allowed for TextPieceTable
-
getMaxRecordLength
public static int getMaxRecordLength()
- Returns:
- the max record length allowed for TextPieceTable
-
newTextPiece
protected TextPiece newTextPiece(int nodeStartChars, int nodeEndChars, byte[] buf, PieceDescriptor pd)
-
add
public void add(TextPiece piece)
-
adjustForInsert
public int adjustForInsert(int listIndex, int length)Adjust all the text piece after inserting some text into one of them- Parameters:
listIndex- The TextPiece that had characters inserted intolength- The number of characters inserted
-
getByteIndex
public int getByteIndex(int charPos)
Description copied from interface:CharIndexTranslatorCalculates the byte index of the given char index.- Specified by:
getByteIndexin interfaceCharIndexTranslator- Parameters:
charPos- The char position- Returns:
- The byte index
-
getCharIndex
@Deprecated public int getCharIndex(int bytePos)
Deprecated.
-
getCharIndex
@Deprecated public int getCharIndex(int startBytePos, int startCP)
Deprecated.
-
getCharIndexRanges
public int[][] getCharIndexRanges(int startBytePosInclusive, int endBytePosExclusive)Description copied from interface:CharIndexTranslatorFinds character ranges that includes specified byte range.- Specified by:
getCharIndexRangesin interfaceCharIndexTranslator- Parameters:
startBytePosInclusive- start byte rangeendBytePosExclusive- end byte range
-
getEncodingMultiplier
protected int getEncodingMultiplier(TextPiece textPiece)
-
getCpMin
public int getCpMin()
-
getText
public StringBuilder getText()
-
isIndexInTable
public boolean isIndexInTable(int bytePos)
Description copied from interface:CharIndexTranslatorCheck if index is in table- Specified by:
isIndexInTablein interfaceCharIndexTranslator- Returns:
- true if index in table, false if not
-
lookIndexBackward
public int lookIndexBackward(int startBytePos)
Description copied from interface:CharIndexTranslatorReturn last index <= bytePos that is in table- Specified by:
lookIndexBackwardin interfaceCharIndexTranslator- Returns:
- last index less of equal to bytePos that is in table
-
lookIndexForward
public int lookIndexForward(int startBytePos)
Description copied from interface:CharIndexTranslatorReturn first index >= bytePos that is in table- Specified by:
lookIndexForwardin interfaceCharIndexTranslator- Returns:
- first index greater or equal to bytePos that is in table
-
writeTo
public byte[] writeTo(ByteArrayOutputStream docStream) throws IOException
- Throws:
IOException
-
-