<commit_before>package net.tomp2p.storage;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

public class DataBuffer {

	private final List<ByteBuf> buffers;

	private int alreadyTransferred = 0;

	public DataBuffer() {
		this(1);
	}
	
	public DataBuffer(int nrArrays) {
		buffers = new ArrayList<ByteBuf>(nrArrays);
	}
	
	public DataBuffer(final byte[] buffer) {
		this(buffer, 0, buffer.length);
	}

	public DataBuffer(final byte[] buffer, final int offset, final int length) {
		buffers = new ArrayList<ByteBuf>(1);
		final ByteBuf buf = Unpooled.wrappedBuffer(buffer, offset, length);
		buffers.add(buf);
		// no need to retain, as we initialized here and ref counter is set to 1
	}

	/**
	 * Creates a DataBuffer and adds the ByteBuf to this DataBuffer
	 * 
	 * @param buf
	 *            The ByteBuf is only added, but no retain() is called!
	 */
	public DataBuffer(final ByteBuf buf) {
		ByteBuf slice = Unpooled.wrappedBuffer(buf);
		buffers = new ArrayList<ByteBuf>(1);
		buffers.add(slice);
	}

	private DataBuffer(final List<ByteBuf> buffers) {
		this.buffers = new ArrayList<ByteBuf>(buffers.size());
		for (final ByteBuf buf : buffers) {
			this.buffers.add(buf.duplicate());
			buf.retain();
		}
	}
	
	public DataBuffer add(DataBuffer dataBuffer) {
		synchronized (buffers) {
			buffers.addAll(dataBuffer.buffers);
		}
		return this;
    }

	// from here, work with shallow copies
	public DataBuffer shallowCopy() {
		final DataBuffer db;
		synchronized (buffers) {
			db = new DataBuffer(buffers);
		}
		return db;
	}
<commit_msg>Revert "DataBuffer leak fixes (in theory)"<commit_after>package net.tomp2p.storage;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

public class DataBuffer {

	private final List<ByteBuf> buffers;

	private int alreadyTransferred = 0;

	public DataBuffer() {
		this(1);
	}
	
	public DataBuffer(int nrArrays) {
		buffers = new ArrayList<ByteBuf>(nrArrays);
	}
	
	public DataBuffer(final byte[] buffer) {
		this(buffer, 0, buffer.length);
	}

	public DataBuffer(final byte[] buffer, final int offset, final int length) {
		buffers = new ArrayList<ByteBuf>(1);
		final ByteBuf buf = Unpooled.wrappedBuffer(buffer, offset, length);
		buffers.add(buf);
		// no need to retain, as we initialized here and ref counter is set to 1
	}

	/**
	 * Creates a DataBuffer and adds the ByteBuf to this DataBuffer
	 * 
	 * @param buf
	 *            The ByteBuf is only added, but no retain() is called!
	 */
	public DataBuffer(final ByteBuf buf) {
		buffers = new ArrayList<ByteBuf>(1);
		buffers.add(buf.slice());
		buf.retain();
	}

	private DataBuffer(final List<ByteBuf> buffers) {
		this.buffers = new ArrayList<ByteBuf>(buffers.size());
		for (final ByteBuf buf : buffers) {
			this.buffers.add(buf.duplicate());
			buf.retain();
		}
	}
	
	public DataBuffer add(DataBuffer dataBuffer) {
		synchronized (buffers) {
			buffers.addAll(dataBuffer.buffers);
		}
		return this;
    }

	// from here, work with shallow copies
	public DataBuffer shallowCopy() {
		final DataBuffer db;
		synchronized (buffers) {
			db = new DataBuffer(buffers);
		}
		return db;
	}

{'fraction_non_alphanumeric': 0.11320754716981132, 'fraction_numerical': 0.00426049908703591, 'mean_word_length': 3.876854599406528, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7482718', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1068, 'n_words': 301}