Package uicc.suspendresume
Class SuspendUtil
- java.lang.Object
-
- uicc.suspendresume.SuspendUtil
-
public class SuspendUtil extends java.lang.ObjectTheSuspendUtilclass contains utility methods to compare and manipulate time formated as in the SUSPEND UICC command defined in TS 102 221. TheTimeUnitneeded for the UICC SUSPEND command, is encoded in seconds, minutes, hours, days and ten days indicating the duration of suspension.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static shortsecondsToTime(byte[] bArray, short bOff, short bLen)This method converts the time encoded in the byte arraybArrayin seconds provided as an unsigned integer to theshortvalue which is composed of the concatenation ofTimeUnitandTimeValue.
TheTimeUnitneeded for the UICC SUSPEND command, is encoded in seconds, minutes, hours, days and ten days indicating the duration of suspension.
The value in the array shall be big endian encoded, i.e.static booleantimeCompare(byte TimeUnit1, short TimeValue1, short CompareOperation, byte TimeUnit2, short TimeValue2)This method compares two provided timesTime1(composed ofTimeUnit1andTimeValue1) andTime2(composed ofTimeUnit2andTimeValue2) according to the comparison method requested encoded inCompareOperation.static shorttimeToSeconds(byte TimeUnit, short TimeValue, byte[] bArray, short bOff)This method converts the provided timeTime(composed ofTimeUnitandTimeValue) to a value in seconds in the destination arraybArray.
The value in the array is an unsigned integer which is big endian encoded i.e.
-
-
-
Method Detail
-
timeCompare
public static final boolean timeCompare(byte TimeUnit1, short TimeValue1, short CompareOperation, byte TimeUnit2, short TimeValue2) throws SuspendExceptionThis method compares two provided timesTime1(composed ofTimeUnit1andTimeValue1) andTime2(composed ofTimeUnit2andTimeValue2) according to the comparison method requested encoded inCompareOperation.- Parameters:
TimeUnit1- time unit of Time1 defined inTIME_UNIT_XXX.TimeValue1- time value of Time1.CompareOperation- comparison method defined inCOMPARE_IS_XXX.TimeUnit2- time unit of Time2 defined inTIME_UNIT_XXX.TimeValue2- time value of Time2.- Returns:
truefor comparison methodCOMPARE_IS_EQUALif Time1 and Time2 are equal.truefor comparison methodCOMPARE_IS_LOWERif Time1 is strictly lower than Time2.truefor comparison methodCOMPARE_IS_HIGHERif Time1 is strictly higher than Time2.truefor comparison methodCOMPARE_IS_NOT_EQUALif the values are not equal.
- Throws:
SuspendException- with the following reason codes:UNEXPECTED_TIME_UNITif eitherTimeUnit1orTimeUnit2or both are not defined inSuspendConstantsUNEXPECTED_COMPAREifCompareOperationis not defined inSuspendConstants
-
timeToSeconds
public static final short timeToSeconds(byte TimeUnit, short TimeValue, byte[] bArray, short bOff) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.NullPointerException, SuspendExceptionThis method converts the provided timeTime(composed ofTimeUnitandTimeValue) to a value in seconds in the destination arraybArray.
The value in the array is an unsigned integer which is big endian encoded i.e. with the MSB byte inbOffand the LSB byte inbOff+bLen-1,bLenis the number of bytes needed to representTimein an unsigned integer. The value ofbLenis between 1 to 4.- Parameters:
TimeUnit- time unit of Time defined inTIME_UNIT_XXX.TimeValue- time value of Time.bArray- destination byte array.bOff- offset within destination byte array.- Returns:
bOff+bLenwherebLenis the the number of bytes set in the array.- Throws:
SuspendException- with the reason codes:UNEXPECTED_TIME_UNITifTimeUnitis not defined inSuspendConstants
java.lang.ArrayIndexOutOfBoundsException- if thebOffparameter is negative or ifbOff+bLenis greater than the length ofbArrayjava.lang.NullPointerException- if thebArrayparameter isnull
-
secondsToTime
public static final short secondsToTime(byte[] bArray, short bOff, short bLen) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.NullPointerException, SuspendExceptionThis method converts the time encoded in the byte arraybArrayin seconds provided as an unsigned integer to theshortvalue which is composed of the concatenation ofTimeUnitandTimeValue.
TheTimeUnitneeded for the UICC SUSPEND command, is encoded in seconds, minutes, hours, days and ten days indicating the duration of suspension.
The value in the array shall be big endian encoded, i.e. with the MSB byte inbOffand the LSB byte inbOff+bLen-1where the value ofbLenis between 1 to 4.
The methodsecondsToTimeconverts the suspension time given in seconds to the most appropriate value and unit.
The strategy for the conversion work as follows:- Use the smallest possible
TimeUnitin order to achieve the best possible resolution, - The value of
TimeValuein the resulting unit should be chosen to minimize the inaccuracy with the value provided as input in seconds, however, the method to minimize this inaccuracy is implementation dependent. - Upon switching to the next higher
TimeUnittheTimeValuein seconds from which the nextTimeUnitis used is determined in such a way that the resulting inaccuracy from the conversion is miminized: as a result values of 256 to 277 seconds are encoded as 255 seconds while 278 seconds and up are encoded in 5 minutes and higher, ...
For details see the following table:
TimeUnitselectionInput range in seconds Output Unit Output range Minimum Maximum Minimum Maximum Dec Hex Dec Hex Dec Hex Dec Hex 00x002770x0115TIME_UNIT_SECONDS00x002550xFF2780x116166500x410ATIME_UNIT_MINUTES50x052550xFF166510x410B9342000x0E4138TIME_UNIT_HOURS50x052550xFF9342010x0E4139222480000x01537A40TIME_UNIT_DAYS110x0B2550xFF222480010x01537A412211839990x0D2EFFFFTIME_UNIT_TEN_DAYS260x1A2550xFF- Parameters:
bArray- destination byte array.bOff- offset within destination byte array.bLen- length within destination byte array.- Returns:
- Encoded Time as:
- In MSB byte: the time unit selected from the predefined
constants
TIME_UNIT_XXXininterfaceSuspendConstants - In LSB byte: the maximum acceptable time value as an unsigned byte.
- In MSB byte: the time unit selected from the predefined
constants
- Throws:
SuspendException- with the reason codeUNEXPECTED_OVERFLOWif the provided value in seconds is above the maximum available (221183999 or 0x0D2EFFFF seconds corresponding to 256 times ten days minus 1 second).java.lang.ArrayIndexOutOfBoundsException- if thebOffparameter is negative or ifbOff+bLenis greater than the length ofbArrayjava.lang.NullPointerException- if thebArrayparameter isnull
- Use the smallest possible
-
-