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

lowentry.ue4.classes.bitdata.writer.BitBufferDataWriter Maven / Gradle / Ivy

There is a newer version: 9.9.9.DELETED
Show newest version
package lowentry.ue4.classes.bitdata.writer;


import java.nio.ByteBuffer;

import lowentry.ue4.classes.BitDataWriter;


public class BitBufferDataWriter extends BitDataWriter
{
	protected final ByteBuffer	bytes;
	
	
	public BitBufferDataWriter(ByteBuffer buffer)
	{
		buffer.clear();
		this.bytes = buffer;
	}
	
	
	@Override
	protected byte[] getBytesImplementation()
	{
		ByteBuffer shallowCopy = getByteBufferImplementation();
		byte[] b = new byte[shallowCopy.remaining()];
		shallowCopy.get(b);
		return b;
	}
	
	@Override
	protected byte[] getBytesImplementation(byte addByteToEnd)
	{
		ByteBuffer shallowCopy = getByteBufferImplementation(addByteToEnd);
		byte[] b = new byte[shallowCopy.remaining()];
		shallowCopy.get(b);
		return b;
	}
	
	@Override
	public ByteBuffer getByteBufferImplementation()
	{
		ByteBuffer shallowCopy = bytes.duplicate();
		shallowCopy.flip();
		return shallowCopy;
	}
	
	/**
	 * NOTICE: Adding new data to this BitDataWriter will cause the returned ByteBuffer to no longer be valid, because the last byte of the returned ByteBuffer will be overwritten!
	 */
	@Override
	public ByteBuffer getByteBufferImplementation(byte addByteToEnd)
	{
		ByteBuffer shallowCopy = bytes.duplicate();
		shallowCopy.put(addByteToEnd);
		shallowCopy.flip();
		return shallowCopy;
	}
	
	
	@Override
	protected void resetImplementation()
	{
		bytes.clear();
	}
	
	
	@Override
	protected void addRawByteImplementation(byte value)
	{
		bytes.put(value);
	}
	
	@Override
	protected void addRawBytesImplementation(byte[] value)
	{
		if(value == null)
		{
			return;
		}
		bytes.put(value);
	}
	
	
	@Override
	protected void addingUnsafeImplementation(int count)
	{
	}
	
	@Override
	protected void addRawByteUnsafeImplementation(byte value)
	{
		bytes.put(value);
	}
	
	@Override
	protected void addRawBytesUnsafeImplementation(byte[] value)
	{
		if(value == null)
		{
			return;
		}
		bytes.put(value);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy