Class JCint
- java.lang.Object
-
- javacardx.framework.util.intx.JCint
-
public final class JCint extends Object
TheJCintclass contains common utility functions using ints. Some of the methods may be implemented as native functions for performance reasons. All the methods inJCintclass 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 theJCSystemclass.- Since:
- 2.2.2
- See Also:
javacard.framework.JCSystem
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetInt(byte[] bArray, short bOff)Concatenates four bytes in a byte array to form a int value.static intmakeInt(byte b1, byte b2, byte b3, byte b4)Concatenates the four parameter bytes to form an int value.static intmakeInt(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 specifiedarrayparameter.static int[]makeTransientIntArray(short length, byte event)Creates a transient int array with the specified array length.static shortsetInt(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, ArrayIndexOutOfBoundsExceptionConcatenates 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 thebArrayparameter isnullArrayIndexOutOfBoundsException- if thebOffparameter is negative or ifbOff+4is greater than the length ofbArray
-
setInt
public static final short setInt(byte[] bArray, short bOff, int iValue) throws TransactionException, NullPointerException, ArrayIndexOutOfBoundsExceptionDeposits 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+4Note:
- If the byte array is persistent, this operation is performed atomically.
If the commit capacity is exceeded, no operation is performed and a
TransactionExceptionexception 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 thebArrayparameter isnullArrayIndexOutOfBoundsException- if thebOffparameter is negative or ifbOff+4is greater than the length ofbArray- See Also:
javacard.framework.JCSystem.getUnusedCommitCapacity()
-
makeTransientIntArray
public static int[] makeTransientIntArray(short length, byte event) throws NegativeArraySizeException, SystemExceptionCreates 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 thelengthparameter is negativeSystemException- with the following reason codes:SystemException.ILLEGAL_VALUEif event is not a valid event code.SystemException.NO_TRANSIENT_SPACEif sufficient transient space is not available.SystemException.ILLEGAL_TRANSIENTif the current applet context is not the currently selected applet context andCLEAR_ON_DESELECTis 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 specifiedarrayparameter. 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
arrayparameter 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 aSecurityExceptionATTR_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
arrayparameter:- Any attempt to create a view with the
ATTR_READABLE_VIEWattribute will throw aSecurityExceptionif thearrayparameter is not readable. - Any attempt to create a view with the
ATTR_WRITABLE_VIEWattribute will throw aSecurityExceptionif thearrayparameter 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
SecurityExceptionExample:
// 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 thearraywhere the view startslength- the number of elements in the viewattributes- the view access attributes (combinations ofATTR_READABLE_VIEWandATTR_WRITABLE_VIEWattributes)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 specifiedserviceand 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
arrayparameter - Throws:
NullPointerException- if thearrayparameter isnullNegativeArraySizeException- if thelengthparameter is negativeSecurityException-- if the
arraycannot be accessed from current context - if requesting access attributes that were not available for
the
arrayparameter
- if the
SystemException- with the following reason code:SystemException.ILLEGAL_VALUEif thearrayparameter is not an arraySystemException.NO_RESOURCEif not enough resources to allocate the view
ArrayIndexOutOfBoundsException- if the view would cause access of data outside array bounds- Since:
- 3.1
-
-