1 7 8 package javax.naming; 9 10 40 41 45 46 public class BinaryRefAddr extends RefAddr { 47 53 private byte[] buf = null; 54 55 63 public BinaryRefAddr(String addrType, byte[] src) { 64 this(addrType, src, 0, src.length); 65 } 66 67 79 public BinaryRefAddr(String addrType, byte[] src, int offset, int count) { 80 super(addrType); 81 buf = new byte[count]; 82 System.arraycopy(src, offset, buf, 0, count); 83 } 84 85 94 public Object getContent() { 95 return buf; 96 } 97 98 99 106 public boolean equals(Object obj) { 107 if ((obj != null) && (obj instanceof BinaryRefAddr )) { 108 BinaryRefAddr target = (BinaryRefAddr )obj; 109 if (addrType.compareTo(target.addrType) == 0) { 110 if (buf == null && target.buf == null) 111 return true; 112 if (buf == null || target.buf == null || 113 buf.length != target.buf.length) 114 return false; 115 for (int i = 0; i < buf.length; i++) 116 if (buf[i] != target.buf[i]) 117 return false; 118 return true; 119 } 120 } 121 return false; 122 } 123 124 133 public int hashCode() { 134 int hash = addrType.hashCode(); 135 for (int i = 0; i < buf.length; i++) { 136 hash += buf[i]; } 138 return hash; 139 } 140 141 150 public String toString(){ 151 StringBuffer str = new StringBuffer ("Address Type: " + addrType + "\n"); 152 153 str.append("AddressContents: "); 154 for (int i = 0; i<buf.length && i < 32; i++) { 155 str.append(Integer.toHexString(buf[i]) +" "); 156 } 157 if (buf.length >= 32) 158 str.append(" ...\n"); 159 return (str.toString()); 160 } 161 162 165 private static final long serialVersionUID = -3415254970957330361L; 166 } 167 | Popular Tags |