/** * Returns the length, in characters */ @Deprecated public int characterLength() { return (getEnd() - getStart()); }
/** * Returns the length, in bytes */ public int bytesLength() { return (getEnd() - getStart()) * (_usesUnicode ? 2 : 1); }
/** * Returns the length, in characters */ @Deprecated public int characterLength() { return (getEnd() - getStart()); } /**
/** * Returns the length, in bytes */ public int bytesLength() { return (getEnd() - getStart()) * (_usesUnicode ? 2 : 1); }
public String toString() { return "TextPiece from " + getStart() + " to " + getEnd() + " (" + getPieceDescriptor() + ")"; } }
public String toString() { return "TextPiece from " + getStart() + " to " + getEnd() + " (" + getPieceDescriptor() + ")"; }
/** * Adjust all the text piece after inserting some text into one of them * * @param listIndex The TextPiece that had characters inserted into * @param length The number of characters inserted */ public int adjustForInsert(int listIndex, int length) { int size = _textPieces.size(); TextPiece tp = _textPieces.get(listIndex); // Update with the new end tp.setEnd(tp.getEnd() + length); // Now change all subsequent ones for (int x = listIndex + 1; x < size; x++) { tp = _textPieces.get(x); tp.setStart(tp.getStart() + length); tp.setEnd(tp.getEnd() + length); } // All done return length; }
/** * Adjusts the internal string for deletinging * some characters within this. * * @param start The start position for the delete, in characters * @param length The number of characters to delete */ @Deprecated public void adjustForDelete(int start, int length) { int myStart = getStart(); int myEnd = getEnd(); int end = start + length; /* do we have to delete from this text piece? */ if (start <= myEnd && end >= myStart) { /* find where the deleted area overlaps with this text piece */ int overlapStart = Math.max(myStart, start); int overlapEnd = Math.min(myEnd, end); int bufStart = overlapStart - myStart; int bufEnd = overlapEnd - myStart; ((StringBuilder) _buf).delete(bufStart, bufEnd); } // We need to invoke this even if text from this piece is not being // deleted because the adjustment must propagate to all subsequent // text pieces i.e., if text from tp[n] is being deleted, then // tp[n + 1], tp[n + 2], etc. will need to be adjusted. // The superclass is expected to use a separate sentry for this. super.adjustForDelete(start, length); }
/** * Adjusts the internal string for deletinging * some characters within this. * @param start The start position for the delete, in characters * @param length The number of characters to delete */ @Deprecated public void adjustForDelete(int start, int length) { int numChars = length; int myStart = getStart(); int myEnd = getEnd(); int end = start + numChars; /* do we have to delete from this text piece? */ if (start <= myEnd && end >= myStart) { /* find where the deleted area overlaps with this text piece */ int overlapStart = Math.max(myStart, start); int overlapEnd = Math.min(myEnd, end); int bufStart = overlapStart - myStart; int bufEnd = overlapEnd - myStart; ((StringBuilder)_buf).delete(bufStart, bufEnd); } // We need to invoke this even if text from this piece is not being // deleted because the adjustment must propagate to all subsequent // text pieces i.e., if text from tp[n] is being deleted, then // tp[n + 1], tp[n + 2], etc. will need to be adjusted. // The superclass is expected to use a separate sentry for this. super.adjustForDelete(start, length); }
/** * Adjust all the text piece after inserting some text into one of them * * @param listIndex * The TextPiece that had characters inserted into * @param length * The number of characters inserted */ public int adjustForInsert( int listIndex, int length ) { int size = _textPieces.size(); TextPiece tp = _textPieces.get( listIndex ); // Update with the new end tp.setEnd( tp.getEnd() + length ); // Now change all subsequent ones for ( int x = listIndex + 1; x < size; x++ ) { tp = _textPieces.get( x ); tp.setStart( tp.getStart() + length ); tp.setEnd( tp.getEnd() + length ); } // All done return length; }
public StringBuilder getText() { final long start = System.currentTimeMillis(); // rebuild document paragraphs structure StringBuilder docText = new StringBuilder(); for (TextPiece textPiece : _textPieces) { String toAppend = textPiece.getStringBuilder().toString(); int toAppendLength = toAppend.length(); if (toAppendLength != textPiece.getEnd() - textPiece.getStart()) { logger.log( POILogger.WARN, "Text piece has boundaries [", Integer.valueOf(textPiece.getStart()), "; ", Integer.valueOf(textPiece.getEnd()), ") but length ", Integer.valueOf(textPiece.getEnd() - textPiece.getStart())); } docText.replace(textPiece.getStart(), textPiece.getStart() + toAppendLength, toAppend); } logger.log(POILogger.DEBUG, "Document text were rebuilded in ", Long.valueOf(System.currentTimeMillis() - start), " ms (", Integer.valueOf(docText.length()), " chars)"); return docText; }
public StringBuilder getText() { final long start = System.currentTimeMillis(); // rebuild document paragraphs structure StringBuilder docText = new StringBuilder(); for ( TextPiece textPiece : _textPieces ) { String toAppend = textPiece.getStringBuilder().toString(); int toAppendLength = toAppend.length(); if ( toAppendLength != textPiece.getEnd() - textPiece.getStart() ) { logger.log( POILogger.WARN, "Text piece has boundaries [", Integer.valueOf( textPiece.getStart() ), "; ", Integer.valueOf( textPiece.getEnd() ), ") but length ", Integer.valueOf( textPiece.getEnd() - textPiece.getStart() ) ); } docText.replace( textPiece.getStart(), textPiece.getStart() + toAppendLength, toAppend ); } logger.log( POILogger.DEBUG, "Document text were rebuilded in ", Long.valueOf( System.currentTimeMillis() - start ), " ms (", Integer.valueOf( docText.length() ), " chars)" ); return docText; }
public int getByteIndex(int charPos) { int byteCount = 0; for (TextPiece tp : _textPieces) { if (charPos >= tp.getEnd()) { byteCount = tp.getPieceDescriptor().getFilePosition() + (tp.getEnd() - tp.getStart()) * (tp.isUnicode() ? 2 : 1); if (charPos == tp.getEnd()) break; continue; } if (charPos < tp.getEnd()) { int left = charPos - tp.getStart(); byteCount = tp.getPieceDescriptor().getFilePosition() + left * (tp.isUnicode() ? 2 : 1); break; } } return byteCount; }
public int getByteIndex( int charPos ) { int byteCount = 0; for ( TextPiece tp : _textPieces ) { if ( charPos >= tp.getEnd() ) { byteCount = tp.getPieceDescriptor().getFilePosition() + ( tp.getEnd() - tp.getStart() ) * ( tp.isUnicode() ? 2 : 1 ); if ( charPos == tp.getEnd() ) break; continue; } if ( charPos < tp.getEnd() ) { int left = charPos - tp.getStart(); byteCount = tp.getPieceDescriptor().getFilePosition() + left * ( tp.isUnicode() ? 2 : 1 ); break; } } return byteCount; }
textPiece.getEnd(), newSprmBuffer ); _textRuns.add( chpx );
public byte[] writeTo(ByteArrayOutputStream docStream) throws IOException { PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes()); // int fcMin = docStream.getOffset(); for (TextPiece next : _textPieces) { PieceDescriptor pd = next.getPieceDescriptor(); int offset = docStream.size(); int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE); if (mod != 0) { mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod; byte[] buf = IOUtils.safelyAllocate(mod, MAX_RECORD_LENGTH); docStream.write(buf); } // set the text piece position to the current docStream offset. pd.setFilePosition(docStream.size()); // write the text to the docstream and save the piece descriptor to // the // plex which will be written later to the tableStream. docStream.write(next.getRawBytes()); // The TextPiece is already in characters, which // makes our life much easier int nodeStart = next.getStart(); int nodeEnd = next.getEnd(); textPlex.addProperty(new GenericPropertyNode(nodeStart, nodeEnd, pd.toByteArray())); } return textPlex.toByteArray(); }
textPiece.getEnd(), newSprmBuffer ); paragraphs.add( papx );
textPiece.getEnd(), newSprmBuffer ); paragraphs.add( papx );
int nodeEnd = next.getEnd(); textPlex.addProperty( new GenericPropertyNode( nodeStart, nodeEnd, pd.toByteArray() ) );