1 package user.commons.nexio.server.protocol;
3 import java.io.IOException;
4 import java.nio.ByteBuffer;
5 import java.nio.ByteOrder;
6 import java.util.Calendar;
8 public class GetExtendedFieldGetRecordDateTimestampCommand extends Command {
10 private final static byte[] GET_EXTENDED_FIELD = { (byte) 0xc9, (byte) 0xc3 };
11 private final static byte[] EXTENDED_FIELD_NUMBER = { (byte) 0 };
13 private byte[] buffer;
14 private byte filetime[];
16 public GetExtendedFieldGetRecordDateTimestampCommand(Connection connection) {
20 private Calendar convertFromFILETIME(byte[] filetime) {
21 Calendar result = Calendar.getInstance();
23 ByteBuffer b = ByteBuffer.wrap(filetime);
24 b.order(ByteOrder.LITTLE_ENDIAN);
25 int lo = b.asIntBuffer().get(0);
26 int hi = b.asIntBuffer().get(1);
28 long wFILETIME = ((long) hi << 32) + lo;
30 final long EPOCH_DIFF = 11644473600000L;
31 final long ms_since_16010101 = wFILETIME / (10000);
32 final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
34 result.setTimeInMillis(ms_since_19700101);
39 public Calendar execute(Id id) throws IOException, ProtocolException {
43 connection.write(GET_EXTENDED_FIELD);
44 connection.write(id.get().getBytes());
45 connection.write(EXTENDED_FIELD_NUMBER);
49 int c = connection.read(buffer, 0, 2);
51 throw getException_InvalidResponseLength(c, 2, 2);
55 if (buffer[0] == (byte) 0xd0 && buffer[1] == (byte) 0xc3) {
56 throw new ProtocolException("ID handle is not found!");
59 if (buffer[0] == (byte) 0xdf && buffer[1] == (byte) 0xc3) {
63 c = connection.read(buffer, 0, 1);
65 int toRead = buffer[0];
67 throw new ProtocolException("Invalid ModifiedTimeStamp's data length: " + toRead);
69 filetime = new byte[8];
70 c = connection.read(filetime, 0, 8);
72 throw getException_InvalidResponseLength(c, 8, 8);
74 ret = convertFromFILETIME(filetime);