org.apache.poi.hwpf.model

## Class TextPiece

- java.lang.Object
- - org.apache.poi.hwpf.model.PropertyNode<TextPiece>
  - - org.apache.poi.hwpf.model.TextPiece

- All Implemented Interfaces:
    java.lang.Comparable<TextPiece>, Duplicatable
  Direct Known Subclasses:
    OldTextPiece, SinglentonTextPiece

      @Internal
      public class TextPiece
      extends PropertyNode<TextPiece>

  Lightweight representation of a text piece. Works in the character domain, not the byte domain, so you need to have turned byte references into character references before getting here.

- - ### Field Summary

    - ### Fields inherited from class org.apache.poi.hwpf.model.PropertyNode

      `_buf, EndComparator, StartComparator`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextPiece(int start, int end, byte[] text, PieceDescriptor pd)`
    `TextPiece(int start, int end, byte[] text, PieceDescriptor pd, int cpStart)`
    `TextPiece(TextPiece other)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `adjustForDelete(int start, int length)` Deprecated.
    `int` | `bytesLength()` Returns the length, in bytes
    `int` | `characterLength()` Deprecated.
    `TextPiece` | `copy()`
    `boolean` | `equals(java.lang.Object o)`
    `int` | `getCP()` Returns the character position we start at.
    `PieceDescriptor` | `getPieceDescriptor()`
    `byte[]` | `getRawBytes()`
    `java.lang.StringBuffer` | `getStringBuffer()` Deprecated.
    `java.lang.StringBuilder` | `getStringBuilder()`
    `int` | `hashCode()`
    `boolean` | `isUnicode()`
    `java.lang.String` | `substring(int start, int end)` Deprecated.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class org.apache.poi.hwpf.model.PropertyNode

      `clone, compareTo, getEnd, getStart, limitsAreEqual, setEnd, setStart`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TextPiece

          public TextPiece(TextPiece other)

    - #### TextPiece

          public TextPiece(int start,
                           int end,
                           byte[] text,
                           PieceDescriptor pd,
                           int cpStart)

      Parameters:
        `start` - Beginning offset in main document stream, in characters.
        `end` - Ending offset in main document stream, in characters.
        `text` - The raw bytes of our text instead

    - #### TextPiece

          public TextPiece(int start,
                           int end,
                           byte[] text,
                           PieceDescriptor pd)

      Parameters:
        `start` - Beginning offset in main document stream, in characters.
        `end` - Ending offset in main document stream, in characters.
        `text` - The raw bytes of our text

  - ### Method Detail

    - #### isUnicode

          public boolean isUnicode()

      Returns:
        If this text piece is unicode

    - #### getPieceDescriptor

          public PieceDescriptor getPieceDescriptor()

    - #### getStringBuffer

          @Deprecated
          public java.lang.StringBuffer getStringBuffer()

      Deprecated.

    - #### getStringBuilder

          public java.lang.StringBuilder getStringBuilder()

    - #### getRawBytes

          public byte[] getRawBytes()

    - #### substring

          @Deprecated
          public java.lang.String substring(int start,
                                                        int end)

      Deprecated.
      Returns part of the string. Works only in characters, not in bytes!
      Parameters:
        `start` - Local start position, in characters
        `end` - Local end position, in characters

    - #### adjustForDelete

          @Deprecated
          public void adjustForDelete(int start,
                                                  int length)

      Deprecated.
      Adjusts the internal string for deletinging some characters within this.
      Overrides:
        `adjustForDelete` in class `PropertyNode<TextPiece>`
      Parameters:
        `start` - The start position for the delete, in characters
        `length` - The number of characters to delete

    - #### characterLength

          @Deprecated
          public int characterLength()

      Deprecated.
      Returns the length, in characters

    - #### bytesLength

          public int bytesLength()

      Returns the length, in bytes

    - #### equals

          public boolean equals(java.lang.Object o)

      Overrides:
        `equals` in class `PropertyNode<TextPiece>`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `PropertyNode<TextPiece>`

    - #### getCP

          public int getCP()

      Returns the character position we start at.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### copy

          public TextPiece copy()

      Specified by:
        `copy` in interface `Duplicatable`
      Specified by:
        `copy` in class `PropertyNode<TextPiece>`
      Returns:
        a deep copy of the implementing class / instance

Copyright 2020 The Apache Software Foundation or its licensors, as applicable.