All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hps.integrator.infrastructure.utils.MessageWriter Maven / Gradle / Ivy

package com.hps.integrator.infrastructure.utils;

import com.hps.integrator.abstractions.IByteConstant;
import com.hps.integrator.abstractions.IStringConstant;

import java.util.ArrayList;
import java.util.List;

public class MessageWriter {
    List buffer;

    public MessageWriter() {
        buffer = new ArrayList();
    }

    public MessageWriter(byte[] bytes){
        buffer = new ArrayList();
        for(byte b: bytes)
            buffer.add(b);
    }

    public void add(Byte b) { buffer.add(b); }

    public void add(IByteConstant constant){
        buffer.add(constant.getByte());
    }

    public void add(IStringConstant constant) {
        for(byte b: constant.getBytes())
            buffer.add(b);
    }

    public void addRange(Byte[] bytes) {
        for(byte b: bytes)
            buffer.add(b);
    }

    public void addRange(byte[] bytes){
        for(byte b: bytes)
            buffer.add(b);
    }

    public void pop(){
        buffer.remove(buffer.size() - 1);
    }

    public byte[] toArray(){
        byte[] b = new byte[buffer.size()];

        Object[] b2 = buffer.toArray();
        for(int i = 0; i < buffer.size(); i++)
            b[i] = (Byte)b2[i];

        return b;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy