♻️ Move output generation to state
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / states / HttpState.java
index 95ea051..76dbc94 100644 (file)
 
 package net.pterodactylus.rhynodge.states;
 
+import static java.util.Arrays.copyOf;
+
 import java.io.UnsupportedEncodingException;
 
+import javax.annotation.Nonnull;
+
 import net.pterodactylus.rhynodge.State;
 import net.pterodactylus.rhynodge.queries.HttpQuery;
 
@@ -61,7 +65,7 @@ public class HttpState extends AbstractState {
                this.uri = uri;
                this.protocolCode = protocolCode;
                this.contentType = contentType;
-               this.rawResult = rawResult;
+               this.rawResult = copyOf(rawResult, rawResult.length);
        }
 
        //
@@ -101,7 +105,12 @@ public class HttpState extends AbstractState {
         * @return The raw result of the reply
         */
        public byte[] rawResult() {
-               return rawResult;
+               return copyOf(rawResult, rawResult.length);
+       }
+
+       @Override
+       public boolean isEmpty() {
+               return rawResult.length == 0;
        }
 
        /**
@@ -119,6 +128,12 @@ public class HttpState extends AbstractState {
                }
        }
 
+       @Nonnull
+       @Override
+       protected String plainText() {
+               return content();
+       }
+
        //
        // STATIC METHODS
        //