Package org.apache.pdfbox.cos
Class COSArray
java.lang.Object
org.apache.pdfbox.cos.COSBase
org.apache.pdfbox.cos.COSArray
- All Implemented Interfaces:
Iterable<COSBase>
,COSUpdateInfo
,COSObjectable
An array of PDFBase objects as part of the PDF document.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccept
(ICOSVisitor visitor) Visitor pattern double dispatch method.void
Add the specified object at the ith location and push the rest to the right.void
This will add an object to the array.void
add
(COSObjectable object) This will add an object to the array.void
addAll
(int i, Collection<COSBase> objectList) Add the specified object at the ith location and push the rest to the right.void
addAll
(Collection<COSBase> objectsList) This will add an object to the array.void
This will add all objects to this array.void
clear()
This will remove all of the objects in the collection.get
(int index) This will get an object from the array.int
getInt
(int index) Get the value of the array as an integer.int
getInt
(int index, int defaultValue) Get the value of the array as an integer, return the default if it does not exist.getName
(int index) Get the value of the array as a string.Get an entry in the array that is expected to be a COSName.getObject
(int index) This will get an object from the array.getString
(int index) Get the value of the array as a string.Get an entry in the array that is expected to be a COSName.void
growToSize
(int size) This will add null values until the size of the array is at least as large as the parameter.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.int
This will return the index of the entry or -1 if it is not found.int
indexOfObject
(COSBase object) This will return the index of the entry or -1 if it is not found.boolean
Get the update state for the COSWriter.iterator()
Get access to the list.remove
(int i) This will remove an element from the array.boolean
This will remove an element from the array.void
removeAll
(Collection<COSBase> objectsList) This will remove all of the objects in the collection.boolean
This will remove an element from the array.void
retainAll
(Collection<COSBase> objectsList) This will retain all of the objects in the collection.void
set
(int index, int intVal) This will set an object at a specific index.void
This will set an object at a specific index.void
set
(int index, COSObjectable object) This will set an object at a specific index.void
setFloatArray
(float[] value) Clear the current contents of the COSArray and set it with the float[].void
setInt
(int index, int value) Set the value in the array as an integer.void
Set the value in the array as a name.void
setNeedToBeUpdated
(boolean flag) Set the update state of the dictionary for the COSWriter.void
Set the value in the array as a string.int
size()
This will get the size of this array.float[]
This will take an COSArray of numbers and convert it to a float[].toList()
Return contents of COSArray as a Java List.toString()
Methods inherited from class org.apache.pdfbox.cos.COSBase
getCOSObject, isDirect, setDirect
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
objects
-
needToBeUpdated
private boolean needToBeUpdated
-
-
Constructor Details
-
COSArray
public COSArray()Constructor.
-
-
Method Details
-
add
This will add an object to the array.- Parameters:
object
- The object to add to the array.
-
add
This will add an object to the array.- Parameters:
object
- The object to add to the array.
-
add
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
This will remove all of the objects in the collection.- Parameters:
objectsList
- The list of objects to remove from the collection.
-
retainAll
This will retain all of the objects in the collection.- Parameters:
objectsList
- The list of objects to retain from the collection.
-
addAll
This will add an object to the array.- Parameters:
objectsList
- The object to add to the array.
-
addAll
This will add all objects to this array.- Parameters:
objectList
- The list of objects to add.
-
addAll
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
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
This will set an object at a specific index.- Parameters:
index
- zero based index into array.object
- The object to set.
-
getObject
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
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
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
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
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
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
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
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
This will remove an element from the array.- Parameters:
i
- The index of the object to remove.- Returns:
- The object that was removed.
-
remove
This will remove an element from the array.- Parameters:
o
- The object to remove.- Returns:
true
if the object was removed,false
otherwise
-
removeObject
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:
true
if the object was removed,false
otherwise
-
toString
-
iterator
Get access to the list. -
indexOf
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
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
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
Visitor pattern double dispatch method.- Specified by:
accept
in classCOSBase
- Parameters:
visitor
- The object to notify when visiting this object.- Returns:
- any object, depending on the visitor implementation, or null
- Throws:
IOException
- If an error occurs while visiting this object.
-
isNeedToBeUpdated
public boolean isNeedToBeUpdated()Description copied from interface:COSUpdateInfo
Get the update state for the COSWriter. This indicates whether an object is to be written when there is an incremental save.- Specified by:
isNeedToBeUpdated
in interfaceCOSUpdateInfo
- Returns:
- the update state.
-
setNeedToBeUpdated
public void setNeedToBeUpdated(boolean flag) Set the update state of the dictionary for the COSWriter. This indicates whether an object is to be written when there is an incremental save.Although the state is set, it has no effect on COSWriter behavior because arrays are always written as direct object. If an array is to be part of an incremental save, then the method should be called for its holding dictionary.
- Specified by:
setNeedToBeUpdated
in interfaceCOSUpdateInfo
- Parameters:
flag
-
-
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
Return contents of COSArray as a Java List.- Returns:
- the COSArray as List
-