Package org.apache.pdfbox.cos
Class COSArray
- java.lang.Object
-
- org.apache.pdfbox.cos.COSBase
-
- org.apache.pdfbox.cos.COSArray
-
- All Implemented Interfaces:
java.lang.Iterable<COSBase>,COSUpdateInfo,COSObjectable
public class COSArray extends COSBase implements java.lang.Iterable<COSBase>, COSUpdateInfo
An array of PDFBase objects as part of the PDF document.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<COSBase>objectsprivate COSUpdateStateupdateState
-
Constructor Summary
Constructors Constructor Description COSArray()Constructor.COSArray(java.util.List<? extends COSObjectable> cosObjectables)Use the given list to initialize the COSArray.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(ICOSVisitor visitor)Visitor pattern double dispatch method.voidadd(int i, COSBase object)Add the specified object at the ith location and push the rest to the right.voidadd(COSBase object)This will add an object to the array.voidadd(COSObjectable object)This will add an object to the array.voidaddAll(int i, java.util.Collection<COSBase> objectList)Add the specified object at the ith location and push the rest to the right.voidaddAll(java.util.Collection<COSBase> objectsList)This will add an object to the array.voidaddAll(COSArray objectList)This will add all objects to this array.voidclear()This will remove all of the objects in the collection.COSBaseget(int index)This will get an object from the array.voidgetIndirectObjectKeys(java.util.Collection<COSObjectKey> indirectObjects)Collects all indirect objects numbers within this COSArray and all included dictionaries.voidgetIndirectObjectKeys(java.util.List<COSObjectKey> indirectObjects)Collects all indirect objects numbers within this COSArray and all included dictionaries.intgetInt(int index)Get the value of the array as an integer.intgetInt(int index, int defaultValue)Get the value of the array as an integer, return the default if it does not exist.java.lang.StringgetName(int index)Get the value of the array as a string.java.lang.StringgetName(int index, java.lang.String defaultValue)Get an entry in the array that is expected to be a COSName.COSBasegetObject(int index)This will get an object from the array.java.lang.StringgetString(int index)Get the value of the array as a string.java.lang.StringgetString(int index, java.lang.String defaultValue)Get an entry in the array that is expected to be a COSName.COSUpdateStategetUpdateState()Returns the currentCOSUpdateStateof thisCOSArray.voidgrowToSize(int size)This will add null values until the size of the array is at least as large as the parameter.voidgrowToSize(int size, COSBase object)This will add the object until the size of the array is at least as large as the parameter.intindexOf(COSBase object)This will return the index of the entry or -1 if it is not found.intindexOfObject(COSBase object)This will return the index of the entry or -1 if it is not found.java.util.Iterator<COSBase>iterator()Get access to the list.static COSArrayofCOSIntegers(java.util.List<java.lang.Integer> integer)This will take a list of integer objects and return a COSArray of COSInteger objects.static COSArrayofCOSNames(java.util.List<java.lang.String> strings)This will take a list of string objects and return a COSArray of COSName objects.static COSArrayofCOSStrings(java.util.List<java.lang.String> strings)This will take a list of string objects and return a COSArray of COSName objects.COSBaseremove(int i)This will remove an element from the array.booleanremove(COSBase o)This will remove an element from the array.voidremoveAll(java.util.Collection<COSBase> objectsList)This will remove all of the objects in the collection.booleanremoveObject(COSBase o)This will remove an element from the array.voidretainAll(java.util.Collection<COSBase> objectsList)This will retain all of the objects in the collection.voidset(int index, int intVal)This will set an object at a specific index.voidset(int index, COSBase object)This will set an object at a specific index.voidset(int index, COSObjectable object)This will set an object at a specific index.voidsetFloatArray(float[] value)Clear the current contents of the COSArray and set it with the float[].voidsetInt(int index, int value)Set the value in the array as an integer.voidsetName(int index, java.lang.String name)Set the value in the array as a name.voidsetString(int index, java.lang.String string)Set the value in the array as a string.intsize()This will get the size of this array.java.util.List<java.lang.String>toCOSNameStringList()This will return a list of names if the COSArray consists of COSNames only.java.util.List<java.lang.Float>toCOSNumberFloatList()This will return a list of float values if the COSArray consists of COSNumbers only.java.util.List<java.lang.Integer>toCOSNumberIntegerList()This will return a list of int values if the COSArray consists of COSNumbers only.java.util.List<java.lang.String>toCOSStringStringList()This will return a list of names if the COSArray consists of COSStrings only.float[]toFloatArray()This will take an COSArray of numbers and convert it to a float[].java.util.List<? extends COSBase>toList()Return contents of COSArray as a Java List.java.lang.StringtoString()-
Methods inherited from class org.apache.pdfbox.cos.COSBase
getCOSObject, getKey, isDirect, setDirect, setKey
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.pdfbox.pdmodel.common.COSObjectable
getCOSObject
-
Methods inherited from interface org.apache.pdfbox.cos.COSUpdateInfo
isNeedToBeUpdated, setNeedToBeUpdated, toIncrement
-
-
-
-
Field Detail
-
objects
private final java.util.List<COSBase> objects
-
updateState
private final COSUpdateState updateState
-
-
Constructor Detail
-
COSArray
public COSArray()
Constructor.
-
COSArray
public COSArray(java.util.List<? extends COSObjectable> cosObjectables)
Use the given list to initialize the COSArray.- Parameters:
cosObjectables- the initial list of COSObjectables
-
-
Method Detail
-
add
public void add(COSBase object)
This will add an object to the array.- Parameters:
object- The object to add to the array.
-
add
public void add(COSObjectable object)
This will add an object to the array.- Parameters:
object- The object to add to the array.
-
add
public void add(int i, COSBase object)Add the specified object at the ith location and push the rest to the right.- Parameters:
i- The index to add at.object- The object to add at that index.
-
clear
public void clear()
This will remove all of the objects in the collection.
-
removeAll
public void removeAll(java.util.Collection<COSBase> objectsList)
This will remove all of the objects in the collection.- Parameters:
objectsList- The list of objects to remove from the collection.
-
retainAll
public void retainAll(java.util.Collection<COSBase> objectsList)
This will retain all of the objects in the collection.- Parameters:
objectsList- The list of objects to retain from the collection.
-
addAll
public void addAll(java.util.Collection<COSBase> objectsList)
This will add an object to the array.- Parameters:
objectsList- The object to add to the array.
-
addAll
public void addAll(COSArray objectList)
This will add all objects to this array.- Parameters:
objectList- The list of objects to add.
-
addAll
public void addAll(int i, java.util.Collection<COSBase> objectList)Add the specified object at the ith location and push the rest to the right.- Parameters:
i- The index to add at.objectList- The object to add at that index.
-
set
public void set(int index, COSBase object)This will set an object at a specific index.- Parameters:
index- zero based index into array.object- The object to set.
-
set
public void set(int index, int intVal)This will set an object at a specific index.- Parameters:
index- zero based index into array.intVal- The object to set.
-
set
public void set(int index, COSObjectable object)This will set an object at a specific index.- Parameters:
index- zero based index into array.object- The object to set.
-
getObject
public COSBase getObject(int index)
This will get an object from the array. This will dereference the object. If the object is COSNull then null will be returned.- Parameters:
index- The index into the array to get the object.- Returns:
- The object at the requested index.
-
get
public COSBase get(int index)
This will get an object from the array. This will NOT dereference the COS object.- Parameters:
index- The index into the array to get the object.- Returns:
- The object at the requested index.
-
getInt
public int getInt(int index)
Get the value of the array as an integer.- Parameters:
index- The index into the list.- Returns:
- The value at that index or -1 if does not exist.
-
getInt
public int getInt(int index, int defaultValue)Get the value of the array as an integer, return the default if it does not exist.- Parameters:
index- The value of the array.defaultValue- The value to return if the value is null.- Returns:
- The value at the index or the defaultValue.
-
setInt
public void setInt(int index, int value)Set the value in the array as an integer.- Parameters:
index- The index into the array.value- The value to set.
-
setName
public void setName(int index, java.lang.String name)Set the value in the array as a name.- Parameters:
index- The index into the array.name- The name to set in the array.
-
getName
public java.lang.String getName(int index)
Get the value of the array as a string.- Parameters:
index- The index into the array.- Returns:
- The name converted to a string or null if it does not exist.
-
getName
public java.lang.String getName(int index, java.lang.String defaultValue)Get an entry in the array that is expected to be a COSName.- Parameters:
index- The index into the array.defaultValue- The value to return if it is null.- Returns:
- The value at the index or defaultValue if none is found.
-
setString
public void setString(int index, java.lang.String string)Set the value in the array as a string.- Parameters:
index- The index into the array.string- The string to set in the array.
-
getString
public java.lang.String getString(int index)
Get the value of the array as a string.- Parameters:
index- The index into the array.- Returns:
- The string or null if it does not exist.
-
getString
public java.lang.String getString(int index, java.lang.String defaultValue)Get an entry in the array that is expected to be a COSName.- Parameters:
index- The index into the array.defaultValue- The value to return if it is null.- Returns:
- The value at the index or defaultValue if none is found.
-
size
public int size()
This will get the size of this array.- Returns:
- The number of elements in the array.
-
remove
public COSBase remove(int i)
This will remove an element from the array.- Parameters:
i- The index of the object to remove.- Returns:
- The object that was removed.
-
remove
public boolean remove(COSBase o)
This will remove an element from the array.- Parameters:
o- The object to remove.- Returns:
trueif the object was removed,falseotherwise
-
removeObject
public boolean removeObject(COSBase o)
This will remove an element from the array. This method will also remove a reference to the object.- Parameters:
o- The object to remove.- Returns:
trueif the object was removed,falseotherwise
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
iterator
public java.util.Iterator<COSBase> iterator()
Get access to the list.- Specified by:
iteratorin interfacejava.lang.Iterable<COSBase>- Returns:
- an iterator over the array elements
-
indexOf
public int indexOf(COSBase object)
This will return the index of the entry or -1 if it is not found.- Parameters:
object- The object to search for.- Returns:
- The index of the object or -1.
-
indexOfObject
public int indexOfObject(COSBase object)
This will return the index of the entry or -1 if it is not found. This method will also find references to indirect objects.- Parameters:
object- The object to search for.- Returns:
- The index of the object or -1.
-
growToSize
public void growToSize(int size)
This will add null values until the size of the array is at least as large as the parameter. If the array is already larger than the parameter then nothing is done.- Parameters:
size- The desired size of the array.
-
growToSize
public void growToSize(int size, COSBase object)This will add the object until the size of the array is at least as large as the parameter. If the array is already larger than the parameter then nothing is done.- Parameters:
size- The desired size of the array.object- The object to fill the array with.
-
accept
public void accept(ICOSVisitor visitor) throws java.io.IOException
Visitor pattern double dispatch method.
-
toFloatArray
public float[] toFloatArray()
This will take an COSArray of numbers and convert it to a float[].- Returns:
- This COSArray as an array of float numbers.
-
setFloatArray
public void setFloatArray(float[] value)
Clear the current contents of the COSArray and set it with the float[].- Parameters:
value- The new value of the float array.
-
toList
public java.util.List<? extends COSBase> toList()
Return contents of COSArray as a Java List.- Returns:
- the COSArray as List
-
toCOSNameStringList
public java.util.List<java.lang.String> toCOSNameStringList()
This will return a list of names if the COSArray consists of COSNames only.- Returns:
- the list of names of the COSArray of COSNames
-
toCOSStringStringList
public java.util.List<java.lang.String> toCOSStringStringList()
This will return a list of names if the COSArray consists of COSStrings only.- Returns:
- the list of names of the COSArray of COSStrings
-
toCOSNumberFloatList
public java.util.List<java.lang.Float> toCOSNumberFloatList()
This will return a list of float values if the COSArray consists of COSNumbers only.- Returns:
- the list of float values of the COSArray of COSNumbers
-
toCOSNumberIntegerList
public java.util.List<java.lang.Integer> toCOSNumberIntegerList()
This will return a list of int values if the COSArray consists of COSNumbers only.- Returns:
- the list of int values of the COSArray of COSNumbers
-
ofCOSIntegers
public static COSArray ofCOSIntegers(java.util.List<java.lang.Integer> integer)
This will take a list of integer objects and return a COSArray of COSInteger objects.- Parameters:
integer- A list of integers- Returns:
- An array of COSInteger objects
-
ofCOSNames
public static COSArray ofCOSNames(java.util.List<java.lang.String> strings)
This will take a list of string objects and return a COSArray of COSName objects.- Parameters:
strings- A list of strings- Returns:
- An array of COSName objects
-
ofCOSStrings
public static COSArray ofCOSStrings(java.util.List<java.lang.String> strings)
This will take a list of string objects and return a COSArray of COSName objects.- Parameters:
strings- A list of strings- Returns:
- An array of COSName objects
-
getUpdateState
public COSUpdateState getUpdateState()
Returns the currentCOSUpdateStateof thisCOSArray.- Specified by:
getUpdateStatein interfaceCOSUpdateInfo- Returns:
- The current
COSUpdateStateof thisCOSArray. - See Also:
COSUpdateState
-
getIndirectObjectKeys
public void getIndirectObjectKeys(java.util.List<COSObjectKey> indirectObjects)
Collects all indirect objects numbers within this COSArray and all included dictionaries. It is used to avoid mixed up object numbers when importing an existing page to another pdf. Expert use only. You might run into an endless recursion if choosing a wrong starting point.- Parameters:
indirectObjects- a list of already found indirect objects.
-
getIndirectObjectKeys
public void getIndirectObjectKeys(java.util.Collection<COSObjectKey> indirectObjects)
Collects all indirect objects numbers within this COSArray and all included dictionaries. It is used to avoid mixed up object numbers when importing an existing page to another pdf. Expert use only. You might run into an endless recursion if choosing a wrong starting point.- Parameters:
indirectObjects- a collection of already found indirect objects.
-
-