andrewzzz said:
I have some problems about converting types..
Why do you need to convert them?
1-What is the fastest way to convert from Calendar to byte array?
What should that byte array satisfy?
Obviosuly, you could serialize the Calendar into a byte array, but
that's hardly fast. On the other hand, it is probably the simplest
to implement when you want to serialize several different objects
into one byte sequence.
Or you could do
long time = calendar.getTimeInMillis();
byte[] timeBytes = new byte[]{
(byte) (time >> 56),
(byte) ((time >> 48) & 255),
(byte) ((time >> 40) & 255),
(byte) ((time >> 32) & 255),
(byte) ((time >> 24) & 255),
(byte) ((time >> 16) & 255),
(byte) ((time >> 8) & 255),
(byte) (time & 255),
};
or something similar.
2-What is the fastst way to convert from String to byte array?
Perhaps
string.getBytes() // or better yet, pick an encoding
Again, it depends on what you need to use it for.
3-How do I convert Certificate to byte array?
java.security.cert.Certificate, javax.security.cert.Certificate,
or another specialization of java.security.Certificate?
Probably either getEncoded() or encode(ByteStream).
4-How do I convert PrivateKey to byte array?
The PrivateKey interface also has a getEncoded() method.
5-How do I merge multiple byte arrays into a bigger one?
byte[] bigArray = new byte[array1.length + array2.length];
System.arraycopy(array1, 0, bigArray, 0, array1.length);
System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
Obviously this is not storing enough information to split the big
array into smaller ones.
I think what is worrying me is your request for a "fastest" way,
since that's probably less understandable and maintainable than
just the simplest way.
/L