Advertisement
Chiddix

DictionaryType

May 31st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package me.rabrg.bencode.type.impl;
  2.  
  3. import java.util.Map;
  4. import java.util.Map.Entry;
  5.  
  6. import me.rabrg.bencode.type.BaseType;
  7.  
  8. public final class DictionaryType implements BaseType {
  9.  
  10.     private final Map<StringType, BaseType> value;
  11.  
  12.     public DictionaryType(final Map<StringType, BaseType> value) {
  13.         this.value = value;
  14.     }
  15.  
  16.     @Override
  17.     public String encode() {
  18.         final StringBuffer encoded = new StringBuffer().append('d');
  19.         for (final Entry<StringType, BaseType> entry : value.entrySet()) {
  20.             encoded.append(entry.getKey().encode()).append(entry.getValue().encode());
  21.         }
  22.         return encoded.append('e').toString();
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement