package com.eactive.eai.transformer.function.convert;

import java.util.Stack;

import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;


/**
 * 길이만큼 Space(0x40)으로 패딩하는 함수.
 * 입력 값은 int, 결과는 byte[]임.
 */
public class EBCDICZEROPAD extends PostfixMathCommand {
    public EBCDICZEROPAD() {
        numberOfParameters = 1;
    }

    public void run(Stack inStack) throws ParseException {
        checkStack(inStack);

        Object param = inStack.pop();
        try {
        	int len = ((Number) param).intValue();
            byte[] value = new byte[len];
            
        	for(int i=0; i<len; i++) {
        		value[i] = (byte)0xF0;
        	}
            inStack.push(value);
        } catch (Exception e) {
            throw new ParseException(e.getMessage(), e);
        }
    }
}
