Top Description Fields Constructors Methods
org.apache.pdfbox.cos

public Class COSArray

extends COSBase
implements Iterable<COSBase>, COSUpdateInfo
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.cos.COSUpdateInfo, org.apache.pdfbox.pdmodel.common.COSObjectable, java.lang.Iterable
Imports
java.io.IOException, java.util.ArrayList, .Collection, .Iterator, .List, java.util.stream.Collectors, org.apache.pdfbox.pdmodel.common.COSObjectable

An array of PDFBase objects as part of the PDF document.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final List<COSBase>
private final COSUpdateState

Constructor Summary

AccessConstructor and Description
public
COSArray()

Constructor.

public
COSArray(List<? extends COSObjectable>
the initial list of COSObjectables
cosObjectables
)

Use the given list to initialize the COSArray.

Method Summary

Modifier and TypeMethod and Description
public void
accept(ICOSVisitor
The object to notify when visiting this object.
visitor
)

Implements abstract org.apache.pdfbox.cos.COSBase.accept.

Visitor pattern double dispatch method.

public void
add(COSBase
The object to add to the array.
object
)

This will add an object to the array.

public void
add(COSObjectable
The object to add to the array.
object
)

This will add an object to the array.

public void
add(int
The index to add at.
i
,
COSBase
The object to add at that index.
object
)

Add the specified object at the ith location and push the rest to the right.

public void
addAll(Collection<COSBase>
The object to add to the array.
objectsList
)

This will add an object to the array.

public void
addAll(COSArray
The list of objects to add.
objectList
)

This will add all objects to this array.

public void
addAll(int
The index to add at.
i
,
Collection<COSBase>
The object to add at that index.
objectList
)

Add the specified object at the ith location and push the rest to the right.

public void
clear()

This will remove all of the objects in the collection.

public COSBase

Returns:

The object at the requested index.
get
(int
The index into the array to get the object.
index
)

This will get an object from the array.

public void
getIndirectObjectKeys(List<COSObjectKey>
a list of already found indirect objects.
indirectObjects
)
Deprecated use getIndirectObjectKeys(Collection) instead

Collects all indirect objects numbers within this COSArray and all included dictionaries.

public void
getIndirectObjectKeys(Collection<COSObjectKey>
a collection of already found indirect objects.
indirectObjects
)

Collects all indirect objects numbers within this COSArray and all included dictionaries.

public int

Returns:

The value at that index or -1 if does not exist.
getInt
(int
The index into the list.
index
)

Get the value of the array as an integer.

public int

Returns:

The value at the index or the defaultValue.
getInt
(int
The value of the array.
index
,
int
The value to return if the value is null.
defaultValue
)

Get the value of the array as an integer, return the default if it does not exist.

public String

Returns:

The name converted to a string or null if it does not exist.
getName
(int
The index into the array.
index
)

Get the value of the array as a string.

public String

Returns:

The value at the index or defaultValue if none is found.
getName
(int
The index into the array.
index
,
String
The value to return if it is null.
defaultValue
)

Get an entry in the array that is expected to be a COSName.

public COSBase

Returns:

The object at the requested index.
getObject
(int
The index into the array to get the object.
index
)

This will get an object from the array.

public String

Returns:

The string or null if it does not exist.
getString
(int
The index into the array.
index
)

Get the value of the array as a string.

public String

Returns:

The value at the index or defaultValue if none is found.
getString
(int
The index into the array.
index
,
String
The value to return if it is null.
defaultValue
)

Get an entry in the array that is expected to be a COSName.

public COSUpdateState

Returns:

The current COSUpdateState of this COSArray.
getUpdateState
()

Implements org.apache.pdfbox.cos.COSUpdateInfo.getUpdateState.

Returns the current COSUpdateState of this COSArray.

public void
growToSize(int
The desired size of the array.
size
)

This will add null values until the size of the array is at least as large as the parameter.

public void
growToSize(int
The desired size of the array.
size
,
COSBase
The object to fill the array with.
object
)

This will add the object until the size of the array is at least as large as the parameter.

public int

Returns:

The index of the object or -1.
indexOf
(COSBase
The object to search for.
object
)

This will return the index of the entry or -1 if it is not found.

public int

Returns:

The index of the object or -1.
indexOfObject
(COSBase
The object to search for.
object
)

This will return the index of the entry or -1 if it is not found.

public Iterator<COSBase>

Returns:

an iterator over the array elements
iterator
()

Implements java.lang.Iterable.iterator.

Get access to the list.

public static COSArray

Returns:

An array of COSInteger objects
ofCOSIntegers
(List<Integer>
A list of integers
integer
)

This will take a list of integer objects and return a COSArray of COSInteger objects.

public static COSArray

Returns:

An array of COSName objects
ofCOSNames
(List<String>
A list of strings
strings
)

This will take a list of string objects and return a COSArray of COSName objects.

public static COSArray

Returns:

An array of COSName objects
ofCOSStrings
(List<String>
A list of strings
strings
)

This will take a list of string objects and return a COSArray of COSName objects.

public COSBase

Returns:

The object that was removed.
remove
(int
The index of the object to remove.
i
)

This will remove an element from the array.

public boolean

Returns:

true if the object was removed, false otherwise
remove
(COSBase
The object to remove.
o
)

This will remove an element from the array.

public void
removeAll(Collection<COSBase>
The list of objects to remove from the collection.
objectsList
)

This will remove all of the objects in the collection.

public boolean

Returns:

true if the object was removed, false otherwise
removeObject
(COSBase
The object to remove.
o
)

This will remove an element from the array.

public void
retainAll(Collection<COSBase>
The list of objects to retain from the collection.
objectsList
)

This will retain all of the objects in the collection.

public void
set(int
zero based index into array.
index
,
COSBase
The object to set.
object
)

This will set an object at a specific index.

public void
set(int
zero based index into array.
index
,
int
The object to set.
intVal
)

This will set an object at a specific index.

public void
set(int
zero based index into array.
index
,
COSObjectable
The object to set.
object
)

This will set an object at a specific index.

public void
setFloatArray(float[]
The new value of the float array.
value
)

Clear the current contents of the COSArray and set it with the float[].

public void
setInt(int
The index into the array.
index
,
int
The value to set.
value
)

Set the value in the array as an integer.

public void
setName(int
The index into the array.
index
,
String
The name to set in the array.
name
)

Set the value in the array as a name.

public void
setString(int
The index into the array.
index
,
String
The string to set in the array.
string
)

Set the value in the array as a string.

public int

Returns:

The number of elements in the array.
size
()

This will get the size of this array.

public List<String>

Returns:

the list of names of the COSArray of COSNames
toCOSNameStringList
()

This will return a list of names if the COSArray consists of COSNames only.

public List<Float>

Returns:

the list of float values of the COSArray of COSNumbers
toCOSNumberFloatList
()

This will return a list of float values if the COSArray consists of COSNumbers only.

public List<Integer>

Returns:

the list of int values of the COSArray of COSNumbers
toCOSNumberIntegerList
()

This will return a list of int values if the COSArray consists of COSNumbers only.

public List<String>

Returns:

the list of names of the COSArray of COSStrings
toCOSStringStringList
()

This will return a list of names if the COSArray consists of COSStrings only.

public float[]

Returns:

This COSArray as an array of float numbers.
toFloatArray
()

This will take an COSArray of numbers and convert it to a float[].

public List<? extends COSBase>

Returns:

the COSArray as List
toList
()

Return contents of COSArray as a Java List.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.pdfbox.cos.COSBase:
getCOSObjectgetKeyisDirectsetDirectsetKey

Field Detail

objectsback to summary
private final List<COSBase> objects
updateStateback to summary
private final COSUpdateState updateState

Constructor Detail

COSArrayback to summary
public COSArray()

Constructor.

COSArrayback to summary
public COSArray(List<? extends COSObjectable> cosObjectables)

Use the given list to initialize the COSArray.

Parameters
cosObjectables:List<? extends COSObjectable>

the initial list of COSObjectables

Method Detail

acceptback to summary
public void accept(ICOSVisitor visitor) throws IOException

Implements abstract org.apache.pdfbox.cos.COSBase.accept.

Visitor pattern double dispatch method.

Parameters
visitor:ICOSVisitor

The object to notify when visiting this object.

Annotations
@Override
Exceptions
IOException:
If an error occurs while visiting this object.
addback to summary
public void add(COSBase object)

This will add an object to the array.

Parameters
object:COSBase

The object to add to the array.

addback to summary
public void add(COSObjectable object)

This will add an object to the array.

Parameters
object:COSObjectable

The object to add to the array.

addback to summary
public void add(int i, COSBase object)

Add the specified object at the ith location and push the rest to the right.

Parameters
i:int

The index to add at.

object:COSBase

The object to add at that index.

addAllback to summary
public void addAll(Collection<COSBase> objectsList)

This will add an object to the array.

Parameters
objectsList:Collection<COSBase>

The object to add to the array.

addAllback to summary
public void addAll(COSArray objectList)

This will add all objects to this array.

Parameters
objectList:COSArray

The list of objects to add.

addAllback to summary
public void addAll(int i, Collection<COSBase> objectList)

Add the specified object at the ith location and push the rest to the right.

Parameters
i:int

The index to add at.

objectList:Collection<COSBase>

The object to add at that index.

clearback to summary
public void clear()

This will remove all of the objects in the collection.

getback to summary
public COSBase get(int index)

This will get an object from the array. This will NOT dereference the COS object.

Parameters
index:int

The index into the array to get the object.

Returns:COSBase

The object at the requested index.

getIndirectObjectKeysback to summary
public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects)

Deprecated

use getIndirectObjectKeys(Collection) instead

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:List<COSObjectKey>

a list of already found indirect objects.

getIndirectObjectKeysback to summary
public void getIndirectObjectKeys(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:Collection<COSObjectKey>

a collection of already found indirect objects.

getIntback to summary
public int getInt(int index)

Get the value of the array as an integer.

Parameters
index:int

The index into the list.

Returns:int

The value at that index or -1 if does not exist.

getIntback to summary
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:int

The value of the array.

defaultValue:int

The value to return if the value is null.

Returns:int

The value at the index or the defaultValue.

getNameback to summary
public String getName(int index)

Get the value of the array as a string.

Parameters
index:int

The index into the array.

Returns:String

The name converted to a string or null if it does not exist.

getNameback to summary
public String getName(int index, String defaultValue)

Get an entry in the array that is expected to be a COSName.

Parameters
index:int

The index into the array.

defaultValue:String

The value to return if it is null.

Returns:String

The value at the index or defaultValue if none is found.

getObjectback to summary
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:int

The index into the array to get the object.

Returns:COSBase

The object at the requested index.

getStringback to summary
public String getString(int index)

Get the value of the array as a string.

Parameters
index:int

The index into the array.

Returns:String

The string or null if it does not exist.

getStringback to summary
public String getString(int index, String defaultValue)

Get an entry in the array that is expected to be a COSName.

Parameters
index:int

The index into the array.

defaultValue:String

The value to return if it is null.

Returns:String

The value at the index or defaultValue if none is found.

getUpdateStateback to summary
public COSUpdateState getUpdateState()

Implements org.apache.pdfbox.cos.COSUpdateInfo.getUpdateState.

Returns the current COSUpdateState of this COSArray.

Returns:COSUpdateState

The current COSUpdateState of this COSArray.

Annotations
@Override
See Also
COSUpdateState
growToSizeback to summary
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:int

The desired size of the array.

growToSizeback to summary
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:int

The desired size of the array.

object:COSBase

The object to fill the array with.

indexOfback to summary
public int indexOf(COSBase object)

This will return the index of the entry or -1 if it is not found.

Parameters
object:COSBase

The object to search for.

Returns:int

The index of the object or -1.

indexOfObjectback to summary
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:COSBase

The object to search for.

Returns:int

The index of the object or -1.

iteratorback to summary
public Iterator<COSBase> iterator()

Implements java.lang.Iterable.iterator.

Get access to the list.

Returns:Iterator<COSBase>

an iterator over the array elements

Annotations
@Override
ofCOSIntegersback to summary
public static COSArray ofCOSIntegers(List<Integer> integer)

This will take a list of integer objects and return a COSArray of COSInteger objects.

Parameters
integer:List<Integer>

A list of integers

Returns:COSArray

An array of COSInteger objects

ofCOSNamesback to summary
public static COSArray ofCOSNames(List<String> strings)

This will take a list of string objects and return a COSArray of COSName objects.

Parameters
strings:List<String>

A list of strings

Returns:COSArray

An array of COSName objects

ofCOSStringsback to summary
public static COSArray ofCOSStrings(List<String> strings)

This will take a list of string objects and return a COSArray of COSName objects.

Parameters
strings:List<String>

A list of strings

Returns:COSArray

An array of COSName objects

removeback to summary
public COSBase remove(int i)

This will remove an element from the array.

Parameters
i:int

The index of the object to remove.

Returns:COSBase

The object that was removed.

removeback to summary
public boolean remove(COSBase o)

This will remove an element from the array.

Parameters
o:COSBase

The object to remove.

Returns:boolean

true if the object was removed, false otherwise

removeAllback to summary
public void removeAll(Collection<COSBase> objectsList)

This will remove all of the objects in the collection.

Parameters
objectsList:Collection<COSBase>

The list of objects to remove from the collection.

removeObjectback to summary
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:COSBase

The object to remove.

Returns:boolean

true if the object was removed, false otherwise

retainAllback to summary
public void retainAll(Collection<COSBase> objectsList)

This will retain all of the objects in the collection.

Parameters
objectsList:Collection<COSBase>

The list of objects to retain from the collection.

setback to summary
public void set(int index, COSBase object)

This will set an object at a specific index.

Parameters
index:int

zero based index into array.

object:COSBase

The object to set.

setback to summary
public void set(int index, int intVal)

This will set an object at a specific index.

Parameters
index:int

zero based index into array.

intVal:int

The object to set.

setback to summary
public void set(int index, COSObjectable object)

This will set an object at a specific index.

Parameters
index:int

zero based index into array.

object:COSObjectable

The object to set.

setFloatArrayback to summary
public void setFloatArray(float[] value)

Clear the current contents of the COSArray and set it with the float[].

Parameters
value:float[]

The new value of the float array.

setIntback to summary
public void setInt(int index, int value)

Set the value in the array as an integer.

Parameters
index:int

The index into the array.

value:int

The value to set.

setNameback to summary
public void setName(int index, String name)

Set the value in the array as a name.

Parameters
index:int

The index into the array.

name:String

The name to set in the array.

setStringback to summary
public void setString(int index, String string)

Set the value in the array as a string.

Parameters
index:int

The index into the array.

string:String

The string to set in the array.

sizeback to summary
public int size()

This will get the size of this array.

Returns:int

The number of elements in the array.

toCOSNameStringListback to summary
public List<String> toCOSNameStringList()

This will return a list of names if the COSArray consists of COSNames only.

Returns:List<String>

the list of names of the COSArray of COSNames

toCOSNumberFloatListback to summary
public List<Float> toCOSNumberFloatList()

This will return a list of float values if the COSArray consists of COSNumbers only.

Returns:List<Float>

the list of float values of the COSArray of COSNumbers

toCOSNumberIntegerListback to summary
public List<Integer> toCOSNumberIntegerList()

This will return a list of int values if the COSArray consists of COSNumbers only.

Returns:List<Integer>

the list of int values of the COSArray of COSNumbers

toCOSStringStringListback to summary
public List<String> toCOSStringStringList()

This will return a list of names if the COSArray consists of COSStrings only.

Returns:List<String>

the list of names of the COSArray of COSStrings

toFloatArrayback to summary
public float[] toFloatArray()

This will take an COSArray of numbers and convert it to a float[].

Returns:float[]

This COSArray as an array of float numbers.

toListback to summary
public List<? extends COSBase> toList()

Return contents of COSArray as a Java List.

Returns:List<? extends COSBase>

the COSArray as List

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override