package org.getopentest.actions.codecs;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.getopentest.base.TestAction;

public class EncodeUtf8 extends TestAction {

    @Override
    public void run() {
        super.run();

        String string = this.readStringArgument("sourceString");

        ByteBuffer encodedBytesBuffer = StandardCharsets.UTF_8.encode(string);
        byte[] encodedBytes = Arrays.copyOfRange(
                encodedBytesBuffer.array(),
                encodedBytesBuffer.arrayOffset(),
                encodedBytesBuffer.limit());

        this.writeOutput("encodedBytes", encodedBytes);
    }
}
