1 package user.commons.nexio.server.protocol;
3 import java.io.IOException;
5 public class GetExtendedIDFromIDHandleCommand extends Command {
7 private static final String INVALID_RESPONSE = "Invalid response length, response should be 2-258 characters long, but 1 got";
8 private final static byte[] GET_EXTENDED_ID_FROM_ID_HANDLE = { (byte) 0xc8, (byte) 0xc3 };
11 public GetExtendedIDFromIDHandleCommand(Connection connection) {
15 public Xid execute(Id id) throws IOException, ProtocolException {
19 connection.write(GET_EXTENDED_ID_FROM_ID_HANDLE);
20 connection.write(id.get().getBytes());
24 int c = connection.read(buffer, 0, 2);
26 throw new ProtocolException(INVALID_RESPONSE);
30 if (buffer[0] == (byte) 0xd0 && buffer[1] == (byte) 0xc3) {
31 throw new ProtocolException("ID handle is not found!");
35 if (buffer[0] == (byte) 0xdf && buffer[1] == (byte) 0xc3) {
39 c = connection.read(buffer, 0, 1);
42 int toRead = buffer[0];
43 buffer = new byte[toRead];
44 c = connection.read(buffer, 0, toRead);
47 throw getException_InvalidXIDLength(toRead, new String(buffer));
50 ret = new Xid(new String(buffer));