Package org.syrup.functions

Source Code of org.syrup.functions.Concat

package org.syrup.functions;

import org.syrup.Context;
import org.syrup.Function;
import org.syrup.Result;
import org.syrup.helpers.DataImpl;
import org.syrup.helpers.ResultImpl;
import org.syrup.helpers.Utils;

import java.util.logging.Logger;

/**
* Concatenates the first and second input (like UNIX cat) to the first output.
*
* @author Robbert van Dalen
*/
public class Concat implements Function
{
    static final String COPYRIGHT = "Copyright 2005 Robbert van Dalen."
        + "At your option, you may copy, distribute, or make derivative works under "
        + "the terms of The Artistic License. This License may be found at "
        + "http://www.opensource.org/licenses/artistic-license.php. "
        + "THERE IS NO WARRANTY; USE THIS PRODUCT AT YOUR OWN RISK.";

    private final static Logger logger = Logger.getLogger("org.syrup.functions.Concat");

    /**
     */
    public Result execute(Context context)
    {
        try
        {
            if (Utils.isFull(context.in_1_link())
                && Utils.isFull(context.in_2_link()))
            {
                byte[] i1 = context.in_1_link().content().bytes();
                byte[] i2 = context.in_2_link().content().bytes();

                byte[] cc = new byte[i1.length
                    + i2.length];

                System.arraycopy(i1, 0, cc, 0, i1.length);
                System.arraycopy(i2, 0, cc, i1.length, i2.length);

                return new ResultImpl(context, true, true, new DataImpl(cc), null);
            }
            else
            {
                throw new Exception("both inputs need to be full");
            }
        }
        catch (Throwable e1)
        {
            return new ResultImpl(context, true, true, null, org.syrup.helpers.Utils.manageError(logger, e1, "Concat error"));
        }
    }
}
TOP

Related Classes of org.syrup.functions.Concat

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.