/**
 * @see <a href=
 *     "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryReceiveMessage.html"
 *     />
 */
public class SendMessageBatchResultEntryHandler
    extends ParseSax.HandlerForGeneratedRequestWithResult<Map.Entry<String, MessageIdAndMD5>> {

  private StringBuilder currentText = new StringBuilder();
  private MessageIdAndMD5.Builder builder = MessageIdAndMD5.builder();
  private String id;

  @Override
  public Entry<String, MessageIdAndMD5> getResult() {
    try {
      return Iterables.getOnlyElement(ImmutableMap.of(id, builder.build()).entrySet());
    } finally {
      builder = MessageIdAndMD5.builder();
    }
  }

  @Override
  public void endElement(String uri, String name, String qName) {
    if (qName.equals("Id")) {
      this.id = currentOrNull(currentText);
    } else if (qName.equals("MessageId")) {
      builder.id(currentOrNull(currentText));
    } else if (qName.equals("MD5OfMessageBody")) {
      builder.md5(HashCode.fromBytes(base16().lowerCase().decode(currentOrNull(currentText))));
    }
    currentText.setLength(0);
  }

  @Override
  public void characters(char ch[], int start, int length) {
    currentText.append(ch, start, length);
  }
}
 @Override
 public Entry<String, MessageIdAndMD5> getResult() {
   try {
     return Iterables.getOnlyElement(ImmutableMap.of(id, builder.build()).entrySet());
   } finally {
     builder = MessageIdAndMD5.builder();
   }
 }