public static <T extends Buffer<T>> long copy(ReadableContainer<T> input, WritableContainer<T> output, T buffer) throws IOException {
		long read = 0;
		long totalCopied = 0;
		// if the output is limited and we know the limit, only read as much as you can write from the input
		// otherwise we are forced to throw an exception when the output is not big enough
		LimitedWritableContainer<T> limitedOutput = output instanceof LimitedWritableContainer ? (LimitedWritableContainer<T>) output : null;
		T target = buffer;
		// resize buffer
		if (limitedOutput != null) {
			if (limitedOutput.remainingSpace() == 0)
				return 0;
			else if (limitedOutput.remainingSpace() < buffer.remainingSpace())
				target = buffer.getFactory().limit(buffer, null, limitedOutput.remainingSpace());
		}
		while ((read = input.read(target)) > 0) {
			output.write(target);
			// the reported amount of bytes written is currently a tricky issue, for example consider the chunked writable container, if you give it 5 bytes, it will first write a header saying that it is gonna write 5 bytes, then the actual bytes
			// in all it might be 10 bytes written which is currently what he is reporting, this however can not be matched to the given 5 bytes
			// it is safer to simply see if all data was read from the target
			if (target.remainingData() > 0)
				throw new IOException("The output container of type " + output.getClass().getName() + " is not big enough to copy the input to");
			totalCopied += read;
			// resize buffer
			if (limitedOutput != null) {
				if (limitedOutput.remainingSpace() == 0)
					break;
				else if (limitedOutput.remainingSpace() < target.remainingSpace())
					target = buffer.getFactory().limit(buffer, null, limitedOutput.remainingSpace());
			}
		}
		return totalCopied;
	}