final Class<?> outcomeClass = this.pendingRequests.peek (token.getMessageId ()).future.outcomeClass;
final Object outcome;
if (outcomeClass == Map.class) {
final Map<String, TValue> values = new HashMap<String, TValue> ();
for (final KVEntry entry : resultEntries) {
final Envelope envelope = entry.getEnvelope ();
final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
final TValue value;
final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
if ((rawValue != null) && (rawValue.length > 0)) {
try {
value = this.encoder.decode (rawValue, encodingMetadata);
} catch (final EncodingException exception) {
this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
this.pendingRequests.fail (token.getMessageId (), exception);
break;
}
} else {
value = null;
}
values.put (entry.getKey (), value);
}
outcome = values;
} else if (outcomeClass == Object.class) {
final TValue value;
if (!resultEntries.isEmpty ()) {
final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
if ((rawValue != null) && (rawValue.length > 0)) {
final Envelope envelope = resultEntries.get (0).getEnvelope ();
final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
try {
value = this.encoder.decode (rawValue, encodingMetadata);
} catch (final EncodingException exception) {
this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
this.pendingRequests.fail (token.getMessageId (), exception);