1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mirrormap.commands;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.ObjectOutputStream;
20 import java.io.Serializable;
21
22 import mirrormap.MirrorMap;
23 import mirrormap.Utils;
24
25
26
27
28
29
30 public abstract class AbstractCommand implements ICommand
31 {
32 private static final long serialVersionUID = 1L;
33
34
35 protected String mirrorMapName;
36
37
38 protected Serializable key;
39
40 public AbstractCommand()
41 {
42 super();
43 }
44
45 public byte[] getBytes()
46 {
47 try
48 {
49 ByteArrayOutputStream bos = new ByteArrayOutputStream();
50 ObjectOutputStream oos = new ObjectOutputStream(bos);
51 oos.writeObject(this);
52 oos.close();
53 return bos.toByteArray();
54 }
55 catch (Exception e)
56 {
57 throw new RuntimeException("Could not serialise "
58 + Utils.safeToString(this), e);
59 }
60 }
61
62 public String getMirrorMapName()
63 {
64 return mirrorMapName;
65 }
66
67 @Override
68 public String toString()
69 {
70 return Utils.string(this, mirrorMapName + ", " + key);
71 }
72 }