Class ASString

  • All Implemented Interfaces:
    java.lang.Comparable
    Direct Known Subclasses:
    ASHexString

    public class ASString
    extends ASObject
    implements java.lang.Comparable
    Represents a pdf string object. That is, a series of bytes that do NOT have an associated encoding.
    • Constructor Summary

      Constructors 
      Constructor Description
      ASString​(byte[] bytes)  
      ASString​(int[] numbers, int bytesToUse, int bytesToPad)
      Construct an ASString from an array of integers.
      ASString​(int[] numbers, int startIndex, int endIndex, int bytesToUse, int bytesToPad)  
      ASString​(java.lang.String javaString)
      Creates an ASString that contains UTF-8.
      ASString​(java.lang.String javaString, java.nio.charset.CharsetEncoder cse)
      Creates an ASString that contains the bytes received by encoding the javaString with the provided cse.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String asString()
      Try to get a chars associated with a byte in this ASString.
      int compareTo​(java.lang.Object anotherString)  
      ASString concat​(ASString addStr)  
      boolean equals​(ASString anotherString)  
      boolean equals​(java.lang.Object anotherString)  
      byte[] getBytes()
      Get the raw bytes associated with this ASString.
      char getChar​(int index)
      Try to get a chars associated with a byte in this ASString.
      char[] getChars()
      Try to get an array of chars associated with this ASString.
      int hashCode()  
      int indexOf​(byte[] key)  
      int lastIndexOf​(int target)  
      ASString substring​(int begin)  
      ASString substring​(int begin, int end)  
      java.lang.String toString()
      Attempts to get a unicode representation for this unencoded string.
      void write​(OutputByteStream outputByteStream)
      Writes the ASString in to the given OutputStream in the format expected by the PDF Spec.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ASString

        public ASString​(byte[] bytes)
      • ASString

        public ASString​(java.lang.String javaString)
        Creates an ASString that contains UTF-8. Note that the fact that this is UTF-8 is promptly forgotten by the instance.
      • ASString

        public ASString​(java.lang.String javaString,
                        java.nio.charset.CharsetEncoder cse)
                 throws PDFInvalidParameterException
        Creates an ASString that contains the bytes received by encoding the javaString with the provided cse. Note that the encoding is promptly forgotten by the instance.
        Throws:
        PDFInvalidParameterException
      • ASString

        public ASString​(int[] numbers,
                        int bytesToUse,
                        int bytesToPad)
                 throws PDFInvalidParameterException
        Construct an ASString from an array of integers.
        Parameters:
        numbers - numbers to use in constructing the ASString
        bytesToUse - number of bytes to use from each number starting with the LSB. Must be from 1 to 4.
        bytesToPad - number of bytes to pad in front of each number beyond the number of bytes taken from each number
        Throws:
        PDFInvalidParameterException - if the bytesToUse is not between 1 and 4
    • Method Detail

      • getBytes

        public byte[] getBytes()
        Get the raw bytes associated with this ASString. The client must NOT alter the returned array.
      • getChars

        public char[] getChars()
        Try to get an array of chars associated with this ASString. Note that, because ASString has no encoding, this just uses a series of heuristics to get the chars. No guarantees are made regarding the returned value other than "we tried our best". It may change over time.
      • getChar

        public char getChar​(int index)
        Try to get a chars associated with a byte in this ASString. Note that, because ASString has no encoding, this just uses a series of heuristics to get the chars. No guarantees are made regarding the returned value other than "we tried our best". It may change over time.
      • asString

        public java.lang.String asString()
        Try to get a chars associated with a byte in this ASString. Note that, because ASString has no encoding, this just uses a series of heuristics to get the chars. No guarantees are made regarding the returned value other than "we tried our best". It may change over time.
      • toString

        public java.lang.String toString()
        Attempts to get a unicode representation for this unencoded string. No guarantees are made about what is returned.
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(java.lang.Object anotherString)
        Specified by:
        compareTo in interface java.lang.Comparable
      • equals

        public boolean equals​(ASString anotherString)
      • equals

        public boolean equals​(java.lang.Object anotherString)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • indexOf

        public int indexOf​(byte[] key)
      • lastIndexOf

        public int lastIndexOf​(int target)
      • substring

        public ASString substring​(int begin)
      • substring

        public ASString substring​(int begin,
                                  int end)