package incheon.res.rdm.com.levylink;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public abstract class LinkVO {
	protected int dataLength;
	

    
    abstract public byte[] getData(); //throws LinkException
    
    public byte[] getBytes(String data, int len) //throws LinkException 
    {
        byte[] buf = null;
        byte[] tbuf = new byte[len];
        
        if (data == null) 
        {
            buf = new byte[len];
            for(int i=0; i<len; ++i) 
            {
                tbuf[i] = (byte)32;//Space
            }
            return tbuf;
        } 
        else 
        {
            try 
            {
                buf = data.getBytes("UTF-8");
            } 
            catch (java.io.UnsupportedEncodingException ex) 
            {
                //throw new LinkException("Illegal Data Encoding");
            }
        }
        
        if (buf.length < len) 
        {
            for(int i=0; i<buf.length; ++i) 
            {
                tbuf[i] = buf[i];
            }
            for(int i=buf.length; i<len; ++i) 
            {
                tbuf[i] = (byte)32;
            }
        }
        else if (buf.length == len) 
        {
            tbuf = buf;
        }
        else if (buf.length > len) 
        {
            //throw new LinkException("Illegal Data Length");
        }
        
        return tbuf;
    }
}