|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectds.ov2.util.Convert_serializable
public class Convert_serializable
Compatibility checking and
data conversion by (ab-)using the APDU_Serializable
interface.
Converts single objects and arrays that are compatible according to
is_compatible_with
.
Contains also the utility methods to convert to and from byte
arrays.
This is a static class.
Constructor Summary | |
---|---|
private |
Convert_serializable()
Static class, object creation disabled. |
Method Summary | |
---|---|
static int |
array_from_bytes(byte[] buf,
int index,
APDU_Serializable[] s)
Deserializes an array of APDU_Serializable's . |
static void |
array_from(PrintWriter out,
String line_start,
APDU_Serializable[] host,
APDU_Serializable[] card)
Converts a card type array into a host type array, possibly verbosely. |
static byte[] |
array_to_bytes(APDU_Serializable[] s)
Serialize an array of APDU_Serializable's
into a byte array. |
static int |
array_to_bytes(APDU_Serializable[] s,
byte[] buf,
int index)
Serialize an array of APDU_Serializable's
into a byte array. |
static void |
array_to(PrintWriter out,
String line_start,
APDU_Serializable[] host,
APDU_Serializable[] card)
Converts a host type array into a card type array, possibly verbosely. |
static void |
check_compatibility(APDU_Serializable[] host,
APDU_Serializable[] card)
Compatibility check for arrays. |
private static void |
convert(APDU_Serializable src,
APDU_Serializable dest)
Converts src into dest on the assumption
that they are compatible and that especially the sizes
are equal. |
static void |
from(APDU_Serializable dest,
APDU_Serializable src)
Converts card type src to host type dest . |
private static void |
output(PrintWriter out,
String line_start,
APDU_Serializable[] a,
int i)
Output serialized data of array element. |
static void |
to(APDU_Serializable src,
APDU_Serializable dest)
Converts host type src to card type dest . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private Convert_serializable()
Method Detail |
---|
private static void convert(APDU_Serializable src, APDU_Serializable dest)
src
into dest
on the assumption
that they are compatible and that especially the sizes
are equal.
src
- sourcedest
- destinationpublic static void to(APDU_Serializable src, APDU_Serializable dest) throws IllegalArgumentException
src
to card type dest
.
Note that in place of to(x, y)
one cannot use
from
(y, x)
in general, because compatibility
need not be symmetric,
see compatibility
checks.
src
- source, host typedest
- destination, card type
IllegalArgumentException
- if
dest.
is_compatible_with
(src)
failspublic static void from(APDU_Serializable dest, APDU_Serializable src) throws IllegalArgumentException
src
to host type dest
.
Note that in place of from(x, y)
one cannot use
to
(y, x)
in general, because compatibility
need not be symmetric,
see compatibility
checks.
dest
- destination, host typesrc
- source, card type
IllegalArgumentException
- if
src.
is_compatible_with
(dest)
failspublic static void check_compatibility(APDU_Serializable[] host, APDU_Serializable[] card) throws IllegalArgumentException, NullPointerException
card[i].
is_compatible_with
(host[i])
for all array elements.
Checks also that the arrays have the same size, of course.
Null references for the arrays or empty arrays are
permissable, as long as the other argument has no elements.
host
- host type arraycard
- card type array
IllegalArgumentException
- if the compatibility check fails
NullPointerException
- if one of the arrays contains a null
referenceprivate static void output(PrintWriter out, String line_start, APDU_Serializable[] a, int i)
a[i]
to out
. The format string
line_start
must contain at most one integer conversion.
It is printed with the index before the data.
out
- the channel to output toline_start
- format string to be printed with i
before
the dataa
- i
- public static void array_to(PrintWriter out, String line_start, APDU_Serializable[] host, APDU_Serializable[] card) throws IllegalArgumentException, NullPointerException
out
if out
is not null
. If out
is null then line_start
is not used. Otherwise
it must be a format string
with at most one integer conversion, which is printed
with the current index to out
before the data.
Note that in place of array_to
one cannot use
array_from
in general, because compatibility
need not be symmetric,
see compatibility
checks.
out
- if not null, channel to print all serialized data toline_start
- not used if out
is null
, otherwise
a format string to be printed with the array index before
the serialized datahost
- source array of host objectscard
- destination array of card objects
IllegalArgumentException
- if the compatibility check fails
NullPointerException
- if one of the arrays contains a null
referencepublic static void array_from(PrintWriter out, String line_start, APDU_Serializable[] host, APDU_Serializable[] card) throws IllegalArgumentException, NullPointerException
out
if out
is not null
. If out
is null then line_start
is not used. Otherwise
it must be a format string
with at most one integer conversion, which is printed
with the current index to out
before the data.
Note that in place of array_from
one cannot use
array_to
in general, because compatibility
need not be symmetric,
see compatibility
checks.
out
- if not null, channel to print all serialized data toline_start
- not used if out
is null
, otherwise
a format string to be printed with the array index before
the serialized datahost
- destination array of host objectscard
- source array of card objects
IllegalArgumentException
- if the compatibility check fails
NullPointerException
- if one of the arrays contains a null
referencepublic static int array_to_bytes(APDU_Serializable[] s, byte[] buf, int index)
APDU_Serializable's
into a byte array.
Asserts that the data of s
fits into buf
at
index
.
s
- the array to serialize, can be null, if non-null all
references in the array must be non-null toobuf
- the byte array to serialize intoindex
- starting index in buf
buf
; this could equal
buf.length
(if the complete buffer is used) or
the original index
argument (if s
is null)
NullPointerException
- if one of the references in the
array s
is nullpublic static byte[] array_to_bytes(APDU_Serializable[] s)
APDU_Serializable's
into a byte array.
s
- the array to serialize, can be null, if non-null all
references in the array must be non-null too
NullPointerException
- if one of the references in the
array s
is nullpublic static int array_from_bytes(byte[] buf, int index, APDU_Serializable[] s)
APDU_Serializable's
. The data is taken starting from index
index
.
buf
- data to deserializeindex
- starting index of datas
- APDU_Serializables
to deserialize,
can be null, if non-null all
references in the array must be non-null too
buf
; this could equal
buf.length
(if the complete buffer is used) or
the original index
argument (if s
is null)
NullPointerException
- if one of the references in s
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |