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 class COSString extends COSBase
This represents a string object in a PDF document.- Version:
- $Revision: 1.30 $
- Author:
- Ben Litchfield
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]BS_ESCAPEBS escape characters.static byte[]CR_ESCAPECR escape characters.static byte[]ESCAPEthe escape character in strings.static byte[]FF_ESCAPEFF escape characters.static byte[]HEX_STRING_CLOSEOne of the close string tokens.static byte[]HEX_STRING_OPENOne of the open string tokens.static byte[]HT_ESCAPEHT escape characters.static byte[]LF_ESCAPELF escape characters.static byte[]STRING_CLOSEOne of the close string tokens.static byte[]STRING_OPENOne of the open string tokens.
-
Constructor Summary
Constructors Constructor Description COSString()Constructor.COSString(boolean isDictionaryValue)Deprecated.Not needed anymore.COSString(byte[] value)Explicit constructor for ease of manual PDF construction.COSString(java.lang.String value)Explicit constructor for ease of manual PDF construction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(ICOSVisitor visitor)visitor pattern double dispatch method.voidappend(byte[] data)This will append a byte[] to the string.voidappend(int in)This will append a byte to the string.static COSStringcreateFromHexString(java.lang.String hex)This will create a COS string from a string of hex characters.static COSStringcreateFromHexString(java.lang.String hex, boolean force)Creates a COS string from a string of hex characters, optionally ignoring malformed input.booleanequals(java.lang.Object obj)byte[]getBytes()This will get the bytes of the string.java.lang.StringgetHexString()This will take this string and create a hex representation of the bytes that make the string.java.lang.StringgetString()This will get the string that this object wraps.inthashCode()voidreset()This will reset the internal buffer.voidsetForceHexForm(boolean v)Forces the string to be written in hexadecimal form instead of literal form.voidsetForceLiteralForm(boolean v)Forces the string to be written in literal form instead of hexadecimal form.java.lang.StringtoString()voidwritePDF(java.io.OutputStream output)This will output this string as a PDF object.-
Methods inherited from class org.apache.pdfbox.cos.COSBase
getCOSObject, getFilterManager, isDirect, isNeedToBeUpdate, setDirect, setNeedToBeUpdate
-
-
-
-
Field Detail
-
STRING_OPEN
public static final byte[] STRING_OPEN
One of the open string tokens.
-
STRING_CLOSE
public static final byte[] STRING_CLOSE
One of the close string tokens.
-
HEX_STRING_OPEN
public static final byte[] HEX_STRING_OPEN
One of the open string tokens.
-
HEX_STRING_CLOSE
public static final byte[] HEX_STRING_CLOSE
One of the close string tokens.
-
ESCAPE
public static final byte[] ESCAPE
the escape character in strings.
-
CR_ESCAPE
public static final byte[] CR_ESCAPE
CR escape characters.
-
LF_ESCAPE
public static final byte[] LF_ESCAPE
LF escape characters.
-
HT_ESCAPE
public static final byte[] HT_ESCAPE
HT escape characters.
-
BS_ESCAPE
public static final byte[] BS_ESCAPE
BS escape characters.
-
FF_ESCAPE
public static final byte[] FF_ESCAPE
FF escape characters.
-
-
Constructor Detail
-
COSString
public COSString()
Constructor.
-
COSString
@Deprecated public COSString(boolean isDictionaryValue)
Deprecated.Not needed anymore. UseCOSString()instead. PDFBOX-1437Constructor.- Parameters:
isDictionaryValue- determines if this string represents a dictionary
-
COSString
public COSString(java.lang.String value)
Explicit constructor for ease of manual PDF construction.- Parameters:
value- The string value of the object.
-
COSString
public COSString(byte[] value)
Explicit constructor for ease of manual PDF construction.- Parameters:
value- The string value of the object.
-
-
Method Detail
-
setForceLiteralForm
public void setForceLiteralForm(boolean v)
Forces the string to be written in literal form instead of hexadecimal form.- Parameters:
v- if v is true the string will be written in literal form, otherwise it will be written in hexa if necessary.
-
setForceHexForm
public void setForceHexForm(boolean v)
Forces the string to be written in hexadecimal form instead of literal form.- Parameters:
v- if v is true the string will be written in hexadecimal form otherwise it will be written in literal if necessary.
-
createFromHexString
public static COSString createFromHexString(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.
-
createFromHexString
public static COSString createFromHexString(java.lang.String hex, boolean force) throws java.io.IOException
Creates a COS string from a string of hex characters, optionally ignoring malformed input.- Parameters:
hex- A hex string.force- flag to ignore malformed input- 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.
-
getHexString
public java.lang.String getHexString()
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.
-
getString
public java.lang.String getString()
This will get the string that this object wraps.- Returns:
- The wrapped string.
-
append
public void append(byte[] data) throws java.io.IOExceptionThis will append a byte[] to the string.- Parameters:
data- The byte[] to add to this string.- Throws:
java.io.IOException- If an IO error occurs while writing the byte.
-
append
public void append(int in) throws java.io.IOExceptionThis will append a byte to the string.- Parameters:
in- The byte to add to this string.- Throws:
java.io.IOException- If an IO error occurs while writing the byte.
-
reset
public void reset()
This will reset the internal buffer.
-
getBytes
public byte[] getBytes()
This will get the bytes of the string.- Returns:
- A byte array that represents the string.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
writePDF
public void writePDF(java.io.OutputStream output) throws java.io.IOExceptionThis will output this string as a PDF object.- Parameters:
output- The stream to write to.- Throws:
java.io.IOException- If there is an error writing to the stream.
-
accept
public java.lang.Object accept(ICOSVisitor visitor) throws COSVisitorException
visitor pattern double dispatch method.- Specified by:
acceptin classCOSBase- Parameters:
visitor- The object to notify when visiting this object.- Returns:
- any object, depending on the visitor implementation, or null
- Throws:
COSVisitorException- If an error occurs while visiting this object.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-