java.lang.Object
org.sejda.sambox.cos.COSBase
org.sejda.sambox.cos.COSString
- All Implemented Interfaces:
COSObjectable,Encryptable
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.
- Author:
- Ben Litchfield, John Hewson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(COSVisitor visitor) Visitor pattern for the COS model objectsbooleanvoidencryptable(boolean encryptable) Sets if the object can be encryptedbooleanbyte[]getBytes()inthashCode()booleanstatic COSStringnewInstance(byte[] value) Factory method for aCOSStringfrom a byte arraystatic COSStringFactory method creating aCOSStringfrom a string of hex characters.static COSStringparseLiteral(String literal) Factory method creating aCOSStringfrom a literal string.voidsetForceHexForm(boolean value) Sets whether or not to force the string is to be written in hex form.voidsetValue(byte[] value) Sets the raw value of this string.toString()Methods inherited from class org.sejda.sambox.cos.COSBase
getCOSObject, hasId, id, idIfAbsent
-
Constructor Details
-
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.
-
-
Method Details
-
setValue
public void setValue(byte[] value) Sets the raw value of this string.- Parameters:
value- The raw bytes of the PDF text string or byte string.
-
setForceHexForm
public void setForceHexForm(boolean value) Sets whether or not to force the string is to be written in hex form. This is needed when signing PDF files.- Parameters:
value- True to force hex.
-
isForceHexForm
public boolean isForceHexForm()- Returns:
- true if the string is to be written in hex form.
-
getString
- Returns:
- the content PDF text string as defined in Chap 7.9 of PDF 32000-1:2008.
-
getBytes
public byte[] getBytes()- Returns:
- the raw bytes of the string. Best used with a PDF byte string.
-
toHexString
- Returns:
- A hex string representing the bytes in this string.
-
encryptable
public boolean encryptable()- Specified by:
encryptablein interfaceEncryptable- Returns:
- true if the can be encrypted
-
encryptable
public void encryptable(boolean encryptable) Description copied from interface:EncryptableSets if the object can be encrypted- Specified by:
encryptablein interfaceEncryptable
-
accept
Description copied from class:COSBaseVisitor pattern for the COS model objects- Specified by:
acceptin classCOSBase- Throws:
IOException
-
equals
-
hashCode
public int hashCode() -
toString
-
newInstance
Factory method for aCOSStringfrom a byte array- Parameters:
value-- Returns:
- a new instance
-
parseLiteral
Factory method creating aCOSStringfrom a literal string.- Parameters:
literal- A literal string.- Returns:
- A
COSStringencoded withPDFDocEncodingencoding if possible, withCharsets#UTF_16BEotherwise. - Throws:
IOException- If there is an error with the hex string.
-
parseHex
Factory method creating aCOSStringfrom a string of hex characters.- Parameters:
hex- A hex string.- Returns:
- A cos string with the hex characters converted to their actual bytes.
- Throws:
IOException- If there is an error with the hex string.
-