jPod PDF library

de.intarsys.pdf.cos
Class COSString

java.lang.Object
  extended by de.intarsys.pdf.cos.COSDocumentElement
      extended by de.intarsys.pdf.cos.COSObject
          extended by de.intarsys.pdf.cos.COSPrimitiveObject
              extended by de.intarsys.pdf.cos.COSString
All Implemented Interfaces:
ICOSExceptionHandler, de.intarsys.tools.component.ISaveStateSupport, Comparable

public class COSString
extends COSPrimitiveObject
implements Comparable

The string representation for a pdf document


Field Summary
 
Fields inherited from class de.intarsys.pdf.cos.COSObject
CONSTANT_CONTAINER, NULL_CONTAINER, SLOT_CONTAINER
 
Method Summary
 Object accept(ICOSObjectVisitor visitor)
          Accept a visitor object.
 COSString asString()
           
 byte[] byteValue()
          The bytes that make up this string.
 void clearBytes()
          Reset the bytes for this COSString.
 void clearString()
          Reset the string value for this COSString.
 int compareTo(Object o)
           
static COSString create(byte[] bytes)
          Create a COSString from bytes.
static COSString create(byte[] bytes, String encoding)
          Create a COSString from bytes.
static COSString create(String string)
          Create a COSString from string.
static COSString create(String string, String encoding)
          Create a COSString from string.
static COSString createHex(byte[] bytes)
          Create a COSString from bytes in hex representation.
static COSString createHex(byte[] bytes, String encoding)
          Create a COSString from bytes in hex representation.
static COSString createHex(String string)
          Create a COSString from string in hex representation.
static COSString createHex(String string, String encoding)
          Create a COSString from string in hex representation.
static COSString createMultiLine(String string)
          Create a COSString from string, escaping all newlines.
 boolean equals(Object o)
           
 String getEncoding()
          Lookup the custom encoding used by this string.
 int hashCode()
           
 String hexStringValue()
          Show a hex encoded representation of the strings content.
 boolean isHexMode()
          true if this string has to be saved as hex representation
 String multiLineStringValue()
          A Java String with correctly expanded newlines.
 void restoreState(Object object)
           
 Object saveState()
           
 void setEncoding(String encoding)
          Set the Charset name to be used when decoding the COSString bytes.
 void setHexMode(boolean newHexMode)
          Set the flag if this is written in hex representation
 String stringValue()
          The Java String representation of the receiver
static String toJavaString(String value)
           
static String toPDFString(String value)
           
 
Methods inherited from class de.intarsys.pdf.cos.COSPrimitiveObject
addObjectListener, basicIterator, copyDeep, copyDeep, isDangling, isObjectListenerAvailable, isPrimitive, iterator, removeObjectListener
 
Methods inherited from class de.intarsys.pdf.cos.COSObject
asArray, asBoolean, asDictionary, asFixed, asInteger, asName, asNull, asNumber, asStream, beConstant, beIndirect, containable, copyOptional, copyShallow, copySubGraph, dereference, getContainer, getDoc, getIndirectObject, getValueBoolean, getValueBytes, getValueFloat, getValueInteger, getValueString, harden, isIndirect, isNull, isNumber, isSwapped, mayBeSwapped, soften, toString
 
Methods inherited from class de.intarsys.pdf.cos.COSDocumentElement
handleException, isReference
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static COSString create(byte[] bytes)
Create a COSString from bytes.

Parameters:
bytes -
Returns:
The new COSString

create

public static COSString create(byte[] bytes,
                               String encoding)
Create a COSString from bytes.

Parameters:
bytes -
Returns:
The new COSString

create

public static COSString create(String string)
Create a COSString from string.

Parameters:
string -
Returns:
The new COSString

create

public static COSString create(String string,
                               String encoding)
Create a COSString from string.

Parameters:
string -
Returns:
The new COSString

createHex

public static COSString createHex(byte[] bytes)
Create a COSString from bytes in hex representation.

Parameters:
bytes -
Returns:
The new COSString

createHex

public static COSString createHex(byte[] bytes,
                                  String encoding)
Create a COSString from bytes in hex representation.

Parameters:
bytes -
Returns:
The new COSString

createHex

public static COSString createHex(String string)
Create a COSString from string in hex representation.

Parameters:
string -
Returns:
The new COSString

createHex

public static COSString createHex(String string,
                                  String encoding)
Create a COSString from string in hex representation.

Parameters:
string -
Returns:
The new COSString

createMultiLine

public static COSString createMultiLine(String string)
Create a COSString from string, escaping all newlines.

Parameters:
string -
Returns:
The new COSString

toJavaString

public static String toJavaString(String value)

toPDFString

public static String toPDFString(String value)

accept

public Object accept(ICOSObjectVisitor visitor)
              throws COSVisitorException
Description copied from class: COSDocumentElement
Accept a visitor object. The receiver selects the correct implementation in the visitor by "double dispatching".

Specified by:
accept in class COSDocumentElement
Parameters:
visitor - The object visiting the receiver.
Returns:
Object An object depending on the visitor semantics.
Throws:
COSVisitorException - An exception depending on the visitor semantics.

asString

public COSString asString()
Overrides:
asString in class COSObject
Returns:
this as a COSString or null

byteValue

public byte[] byteValue()
The bytes that make up this string.

Returns:
The bytes that make up this string.

clearBytes

public void clearBytes()
Reset the bytes for this COSString. You may need this if the encoding is changed during the COSString lifetime.


clearString

public void clearString()
Reset the string value for this COSString. You may need this if the encoding is changed during the COSString lifetime.


compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getEncoding

public String getEncoding()
Lookup the custom encoding used by this string. This method returns null if the default PDF conventions are used.

Be warned: If you use a custom encoding, there is no way for standard PDF tools to recover this information!

Returns:
Lookup the custom encoding used by this string

hashCode

public int hashCode()
Overrides:
hashCode in class Object

hexStringValue

public String hexStringValue()
Show a hex encoded representation of the strings content.

Returns:
Show a hex encoded representation of the strings content.

isHexMode

public boolean isHexMode()
true if this string has to be saved as hex representation

Returns:
true if this string has to be saved as hex representation

multiLineStringValue

public String multiLineStringValue()
A Java String with correctly expanded newlines.

Returns:
A Java String with correctly expanded newlines.

restoreState

public void restoreState(Object object)
Specified by:
restoreState in interface de.intarsys.tools.component.ISaveStateSupport
Overrides:
restoreState in class COSObject

saveState

public Object saveState()
Specified by:
saveState in interface de.intarsys.tools.component.ISaveStateSupport

setEncoding

public void setEncoding(String encoding)
Set the Charset name to be used when decoding the COSString bytes. If no encoding is present, the default PDF conventions are used.

Be warned: If you use a custom encoding, there is no way for standard PDF tools to recover this information!

Parameters:
encoding -

setHexMode

public void setHexMode(boolean newHexMode)
Set the flag if this is written in hex representation

Parameters:
newHexMode - true if this is written in hex representation

stringValue

public String stringValue()
The Java String representation of the receiver

Overrides:
stringValue in class COSObject
Returns:
The Java String representation of the receiver

jPod PDF library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.