<commit_before>package de.fernunihagen.dna.jkn.scalephant.network;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NetworkPackageEncoder {
	
	/**
	 * The sequence number generator 
	 */
	protected final SequenceNumberGenerator sequenceNumberGenerator;
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(NetworkPackageEncoder.class);
	
	
	public NetworkPackageEncoder(final SequenceNumberGenerator sequenceNumberGenerator) {
		this.sequenceNumberGenerator = sequenceNumberGenerator;
	}
	
	/**
	 * Append the package header to the output stream
	 * @param bos
	 */
	protected void appendRequestPackageHeader(final byte packageType, final ByteArrayOutputStream bos) {
		final ByteBuffer byteBuffer = ByteBuffer.allocate(4);
		byteBuffer.order(NetworkConst.NETWORK_BYTEORDER);
		byteBuffer.put(NetworkConst.PROTOCOL_VERSION);
		byteBuffer.put(packageType);
		byteBuffer.putShort(sequenceNumberGenerator.getNextSequenceNummber());

		try {
			bos.write(byteBuffer.array());
		} catch (IOException e) {
			logger.error("Exception while writing", e);
		}
	}
	
	/**
	 * Return a byte arry output stream that contains the header
	 * of the package
	 * @return
	 */
	public ByteArrayOutputStream getOutputStreamForRequestPackage(final byte packageType) {
		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		
		// Append the frame header to the package
		appendRequestPackageHeader(packageType, bos);
		
		return bos;
	}
}
<commit_msg>Added methods for the response header<commit_after>package de.fernunihagen.dna.jkn.scalephant.network;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NetworkPackageEncoder {
	
	/**
	 * The sequence number generator 
	 */
	protected final SequenceNumberGenerator sequenceNumberGenerator;
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(NetworkPackageEncoder.class);
	
	
	public NetworkPackageEncoder(final SequenceNumberGenerator sequenceNumberGenerator) {
		this.sequenceNumberGenerator = sequenceNumberGenerator;
	}
	
	/**
	 * Append the request package header to the output stream
	 * @param packageType
	 * @param bos
	 */
	protected void appendRequestPackageHeader(final byte packageType, final ByteArrayOutputStream bos) {
		final ByteBuffer byteBuffer = ByteBuffer.allocate(4);
		byteBuffer.order(NetworkConst.NETWORK_BYTEORDER);
		byteBuffer.put(NetworkConst.PROTOCOL_VERSION);
		byteBuffer.put(packageType);
		byteBuffer.putShort(sequenceNumberGenerator.getNextSequenceNummber());

		try {
			bos.write(byteBuffer.array());
		} catch (IOException e) {
			logger.error("Exception while writing", e);
		}
	}
	
	/**
	 * Append the response package header to the output stream
	 * @param requestId
	 * @param bos
	 */
	protected void appendResponsePackageHeader(final short requestId, final ByteArrayOutputStream bos) {
		final ByteBuffer byteBuffer = ByteBuffer.allocate(3);
		byteBuffer.order(NetworkConst.NETWORK_BYTEORDER);
		byteBuffer.put(NetworkConst.PROTOCOL_VERSION);
		byteBuffer.putShort(requestId);

		try {
			bos.write(byteBuffer.array());
		} catch (IOException e) {
			logger.error("Exception while writing", e);
		}
	}
	
	/**
	 * Return a byte array output stream for request packages that contains 
	 * the header of the package
	 * @param packageType
	 * @return
	 */
	public ByteArrayOutputStream getOutputStreamForRequestPackage(final byte packageType) {
		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		
		// Append the frame header to the package
		appendRequestPackageHeader(packageType, bos);
		
		return bos;
	}
	
	/**
	 * Return a bate array output stream for response packages that contains
	 * the header of the package
	 * @param packageType
	 * @return
	 */
	public ByteArrayOutputStream getOutputStreamForResponsePackage(final short requestId) {
		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		
		// Append the frame header to the package
		appendResponsePackageHeader(requestId, bos);
		
		return bos;
	}
}

{'fraction_non_alphanumeric': 0.08352996696554979, 'fraction_numerical': 0.0016517225106182161, 'mean_word_length': 4.790983606557377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206467', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1111, 'n_words': 304}