コード例 #1
0
 /** Create a nice readable message for errors */
 private String makeExceptionMessage(IField<?> c, String operation) {
   Object fieldKey = "unknown";
   if (c != null) {
     try {
       fieldKey = new Integer(c.getFieldNumber());
     } catch (Exception ignore) {
     }
   }
   return getClass().getName() + ": Problem " + operation + " field " + fieldKey;
 }
コード例 #2
0
 /** Convert the component into a byte[]. */
 public byte[] pack(IField<?> c) throws MessageException {
   try {
     byte[] data = (byte[]) c.getValue();
     int packedLength = prefixer.getPackedLength();
     if (packedLength == 0) {
       if (data.length != getLength()) {
         throw new MessageException(
             "Binary data length not the same as the packager length ("
                 + data.length
                 + "/"
                 + getLength()
                 + ")");
       }
     }
     byte[] ret = new byte[interpreter.getPackedLength(data.length) + packedLength];
     prefixer.encodeLength(data.length, ret);
     interpreter.interpret(data, ret, packedLength);
     return ret;
   } catch (Exception e) {
     throw new MessageException(makeExceptionMessage(c, "packing"), e);
   }
 }