Package org.apache.pdfbox.cos
Class COSString
- java.lang.Object
-
- org.apache.pdfbox.cos.COSBase
-
- org.apache.pdfbox.cos.COSString
-
- All Implemented Interfaces:
COSObjectable
public final class COSString extends COSBase
A string object, which may be a text string, a PDFDocEncoded string, ASCII string, or byte string.Text strings are used for character strings that contain information intended to be human-readable, such as text annotations, bookmark names, article names, document information, and so forth.
PDFDocEncoded strings are used for characters that are represented in a single byte.
ASCII strings are used for characters that are represented in a single byte using ASCII encoding.
Byte strings are used for binary data represented as a series of bytes, but the encoding is not known. The bytes of the string need not represent characters.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bytesstatic booleanFORCE_PARSINGprivate booleanforceHexFormprivate static org.apache.commons.logging.LogLOG
-
Constructor Summary
Constructors Constructor Description COSString(byte[] bytes)Creates a new PDF string from a byte array.COSString(byte[] bytes, boolean forceHex)Creates a new PDF string from a byte array.COSString(java.lang.String text)Creates a new text string from a Java String.COSString(java.lang.String text, boolean forceHex)Creates a new text string from a Java String.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(ICOSVisitor visitor)Visitor pattern double dispatch method.booleanequals(java.lang.Object obj)java.lang.StringgetASCII()Returns the content of this string as a PDF ASCII string.byte[]getBytes()Returns the raw bytes of the string using a new byte array.booleangetForceHexForm()Returns true if the string is to be written in hex form.java.lang.StringgetString()Returns the content of this string as a PDF text string.inthashCode()static COSStringparseHex(java.lang.String hex)This will create a COS string from a string of hex characters.voidsetForceHexForm(boolean value)Deprecated.to be removed in a future release.voidsetValue(byte[] value)Deprecated.to be removed in a future release.java.lang.StringtoHexString()This will take this string and create a hex representation of the bytes that make the string.java.lang.StringtoString()
-
-
-
Constructor Detail
-
COSString
public COSString(byte[] bytes)
Creates a new PDF string from a byte array. This method can be used to read a string from an existing PDF file, or to create a new byte string.- Parameters:
bytes- The raw bytes of the PDF text string or byte string.
-
COSString
public COSString(byte[] bytes, boolean forceHex)Creates a new PDF string from a byte array. This method can be used to read a string from an existing PDF file, or to create a new byte string.- Parameters:
bytes- The raw bytes of the PDF text string or byte string.forceHex- forces the hexadecimal presentation of the string if set to true
-
COSString
public COSString(java.lang.String text)
Creates a new text string from a Java String.- Parameters:
text- The string value of the object.
-
COSString
public COSString(java.lang.String text, boolean forceHex)Creates a new text string from a Java String.- Parameters:
text- The string value of the object.forceHex- forces the hexadecimal presentation of the string if set to true
-
-
Method Detail
-
parseHex
public static COSString parseHex(java.lang.String hex) throws java.io.IOException
This will create a COS string from a string of hex characters.- Parameters:
hex- A hex string.- Returns:
- A cos string with the hex characters converted to their actual bytes.
- Throws:
java.io.IOException- If there is an error with the hex string.
-
setValue
@Deprecated public void setValue(byte[] value)
Deprecated.to be removed in a future release.Sets the raw value of this string.- Parameters:
value- The raw bytes of the PDF text string or byte string.
-
setForceHexForm
@Deprecated public void setForceHexForm(boolean value)
Deprecated.to be removed in a future release.Sets whether to force the string is to be written in hex form. This is needed when signing PDF files.- Parameters:
value- True to force hex.
-
getForceHexForm
public boolean getForceHexForm()
Returns true if the string is to be written in hex form.- Returns:
- true if the COSString is written in hex form
-
getString
public java.lang.String getString()
Returns the content of this string as a PDF text string.- Returns:
- the PDF string representation of the COSString
-
getASCII
public java.lang.String getASCII()
Returns the content of this string as a PDF ASCII string.- Returns:
- the ASCII string representation of the COSString
-
getBytes
public byte[] getBytes()
Returns the raw bytes of the string using a new byte array. Best used with a PDF byte string.- Returns:
- a clone of the underlying byte[] representation of the COSString
-
toHexString
public java.lang.String toHexString()
This will take this string and create a hex representation of the bytes that make the string.- Returns:
- A hex string representing the bytes in this string.
-
accept
public void accept(ICOSVisitor visitor) throws java.io.IOException
Visitor pattern double dispatch method.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-