Automatically en- and decode peer note texts
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / PeerNote.java
index 7b32207..034e40f 100644 (file)
@@ -18,6 +18,8 @@
 
 package net.pterodactylus.fcp;
 
+import com.google.common.base.Charsets;
+
 /**
  * The “PeerNote” message contains a private note that has been entered for a
  * darknet peer.
@@ -26,6 +28,8 @@ package net.pterodactylus.fcp;
  */
 public class PeerNote extends BaseMessage {
 
+       private static final FreenetBase64 BASE64_DECODER = new FreenetBase64();
+
        /** The type for base64 encoded peer notes. */
        public static final int TYPE_PRIVATE_PEER_NOTE = 1;
 
@@ -35,7 +39,7 @@ public class PeerNote extends BaseMessage {
         * @param receivedMessage
         *            The received message
         */
-       PeerNote(FcpMessage receivedMessage) {
+       public PeerNote(FcpMessage receivedMessage) {
                super(receivedMessage);
        }
 
@@ -54,14 +58,14 @@ public class PeerNote extends BaseMessage {
         * @return The note text
         */
        public String getNoteText() {
-               return getField("NoteText");
+               return new String(BASE64_DECODER.decode(getField("NoteText")), Charsets.UTF_8);
        }
 
        /**
         * Returns the type of the peer note.
         *
-        * @return The type of the peer note, or <code>-1</code> if the type can not
-        *         be parsed
+        * @return The type of the peer note, or <code>-1</code> if the type can
+        *         not be parsed
         */
        public int getPeerNoteType() {
                return FcpUtils.safeParseInt(getField("PeerNoteType"));