Class JCint
- java.lang.Object
-
- javacardx.framework.util.intx.JCint
-
public final class JCint extends Object
TheJCint
class contains common utility functions using ints. Some of the methods may be implemented as native functions for performance reasons. All the methods inJCint
class are static methods.The methods
makeTransientIntArray()
and andsetInt()
, refer to the persistence of array objects. The term persistent means that arrays and their values persist from one CAD session to the next, indefinitely. ThemakeTransientIntArray()
method is used to create transient int arrays. Constants related to transience control are available in theJCSystem
class.- Since:
- 2.2.2
- See Also:
javacard.framework.JCSystem
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getInt(byte[] bArray, short bOff)
Concatenates four bytes in a byte array to form a int value.static int
makeInt(byte b1, byte b2, byte b3, byte b4)
Concatenates the four parameter bytes to form an int value.static int
makeInt(short s1, short s2)
Concatenates the two parameter short values to form an int value.static int[]
makeIntArrayView(int[] array, short offset, short length, short attributes, Shareable service)
Creates an int array which is a view on the specifiedarray
parameter.static int[]
makeTransientIntArray(short length, byte event)
Creates a transient int array with the specified array length.static short
setInt(byte[] bArray, short bOff, int iValue)
Deposits the int value as four successive bytes at the specified offset in the byte array.
-
-
-
Method Detail
-
makeInt
public static final int makeInt(byte b1, byte b2, byte b3, byte b4)
Concatenates the four parameter bytes to form an int value.- Parameters:
b1
- the first byte ( high order byte )b2
- the second byteb3
- the third byteb4
- the fourth byte ( low order byte )- Returns:
- the int value the concatenated result
-
makeInt
public static final int makeInt(short s1, short s2)
Concatenates the two parameter short values to form an int value.- Parameters:
s1
- the first short value ( high order short value )s2
- the second short value ( low order short value )- Returns:
- the int value the concatenated result
-
getInt
public static final int getInt(byte[] bArray, short bOff) throws NullPointerException, ArrayIndexOutOfBoundsException
Concatenates four bytes in a byte array to form a int value.- Parameters:
bArray
- byte arraybOff
- offset within byte array containing first byte (the high order byte)- Returns:
- the int value the concatenated result
- Throws:
NullPointerException
- if thebArray
parameter isnull
ArrayIndexOutOfBoundsException
- if thebOff
parameter is negative or ifbOff+4
is greater than the length ofbArray
-
setInt
public static final short setInt(byte[] bArray, short bOff, int iValue) throws TransactionException, NullPointerException, ArrayIndexOutOfBoundsException
Deposits the int value as four successive bytes at the specified offset in the byte array.- Parameters:
bArray
- byte arraybOff
- offset within byte array to deposit the first byte (the high order byte)iValue
- the short value to set into array.- Returns:
bOff+4
Note:
- If the byte array is persistent, this operation is performed atomically.
If the commit capacity is exceeded, no operation is performed and a
TransactionException
exception is thrown.
- If the byte array is persistent, this operation is performed atomically.
If the commit capacity is exceeded, no operation is performed and a
- Throws:
TransactionException
- if the operation would cause the commit capacity to be exceededNullPointerException
- if thebArray
parameter isnull
ArrayIndexOutOfBoundsException
- if thebOff
parameter is negative or ifbOff+4
is greater than the length ofbArray
- See Also:
javacard.framework.JCSystem.getUnusedCommitCapacity()
-
makeTransientIntArray
public static int[] makeTransientIntArray(short length, byte event) throws NegativeArraySizeException, SystemException
Creates a transient int array with the specified array length.- Parameters:
length
- the length of the int arrayevent
- theCLEAR_ON...
event which causes the array elements to be cleared- Returns:
- the new transient int array
- Throws:
NegativeArraySizeException
- if thelength
parameter is negativeSystemException
- with the following reason codes:SystemException.ILLEGAL_VALUE
if event is not a valid event code.SystemException.NO_TRANSIENT_SPACE
if sufficient transient space is not available.SystemException.ILLEGAL_TRANSIENT
if the current applet context is not the currently selected applet context andCLEAR_ON_DESELECT
is specified.
- See Also:
javacard.framework.JCSystem
-
makeIntArrayView
public static int[] makeIntArrayView(int[] array, short offset, short length, short attributes, Shareable service)
Creates an int array which is a view on the specifiedarray
parameter. The elements of the created array are mapped to the corresponding elements in the parent array. Any change in the parent array will be visible in the view and vice versa.The layout attributes (transient, persistent, sensitive) of the created array are identical to the
array
parameter ones.
In addition, it is possible to create read-only, write-only or R/W views using combinations (bitwise inclusive OR) of the following access attributes:ATTR_READABLE_VIEW
: the elements of the view can be read. If this attribute is not set, any attempt to read elements from the created view will throw aSecurityException
ATTR_WRITABLE_VIEW
: the elements of the view can be modified and changes are visible in the actual array and any other view on it. If this attribute is not set, any attempt to write elements in the created view will throw aSecurityException
The attributes requested for the view shall remain consistent with the attributes of the
array
parameter:- Any attempt to create a view with the
ATTR_READABLE_VIEW
attribute will throw aSecurityException
if thearray
parameter is not readable. - Any attempt to create a view with the
ATTR_WRITABLE_VIEW
attribute will throw aSecurityException
if thearray
parameter is not writable.
The created view is temporary and any attempt to store the reference into a class or instance field or in array elements will throw a
SecurityException
Example:
// creates a R/W view of 5 int on array, starting at offset 4 int[] view = JCint.makeIntArrayView(array, (short) 4, (short) 5, (short) (ATTR_READABLE_VIEW | ATTR_WRITABLE_VIEW), null); // creates a view in the service context and share it with the service int[] view = JCint.makeIntArrayView(array, (short) 4, (short) 5, (short) (ATTR_READABLE_VIEW | ATTR_WRITABLE_VIEW), service); service.execute(view);
- Parameters:
array
- the array on which to create the view (either an actual array or a view)offset
- the offset in thearray
where the view startslength
- the number of elements in the viewattributes
- the view access attributes (combinations ofATTR_READABLE_VIEW
andATTR_WRITABLE_VIEW
attributes)service
- the shareable object identifying the recipient context of the new view. Ifnull
, the view will remain in the current context. If non-null
, the method returns an object created in the context of the specifiedservice
and should be used as parameter when calling methods of thisservice
. Other operations executed in current context, including casting, will throw aSecurityException
.- Returns:
- a view on the specified
array
parameter - Throws:
NullPointerException
- if thearray
parameter isnull
NegativeArraySizeException
- if thelength
parameter is negativeSecurityException
-- if the
array
cannot be accessed from current context - if requesting access attributes that were not available for
the
array
parameter
- if the
SystemException
- with the following reason code:SystemException.ILLEGAL_VALUE
if thearray
parameter is not an arraySystemException.NO_RESOURCE
if not enough resources to allocate the view
ArrayIndexOutOfBoundsException
- if the view would cause access of data outside array bounds- Since:
- 3.1
-
-