A Java library used for efficiently and safely working with ByteBuffers.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.settings
Source/org/magnos/io
Testing/org/magnos/io
build
.classpath
.gitignore
.project
LICENSE.txt
README.md
build.xml
javadoc.xml

README.md

buffero

Stable

A Java library used for efficiently working with ByteBuffers.

Features

  • A way to write to ByteBuffers that avoids BufferOverflow and BufferUnderflow exceptions. This means the object you write to either resizes the underlying buffer or has a chain of buffers, and the object you read from is marked as invalid if there isn't enough data - and default values are returned.
  • BufferFactory has several implementations to quickly allocate, cache, reuse, and dispose of ByteBuffers

Documentation

Example

// A listener to the buffer stream when flush is invoked.
BufferStreamListener listener = ...;

// A factory to manage buffers
BufferFactory buffers = new BufferFactoryBinary(8, 14);

// A stream of data which can expand
BufferStream stream = new BufferStream(listener, buffers);

// Write data to the stream
ByteWriter out = new ByteWriter(stream);
out.putBoolean(true);
out.putUint(234L);
out.putString("Meow");
out.putObject(new BigDecimal("3.323215235123"));
out.putFloatArray(new float[] {4.5f, 1f});
out.putIntArray(null);

// Read data from the stream
ByteReader in = new ByteReader(stream);
boolean d0 = in.getBoolean();               // true
long d1 = in.getUint();                     // 234
String d2 = in.getString();                 // "Meow" 
BigDecimal d3 = in.getCastObject();         // 3.323215235123
float[] d4 = in.getFloatArray();            // {4.5f, 1f}
int[] d5 = in.getIntArray();                // null

// in.isValid() == true, read more than the stream has then check
long[] d6 = in.getUint(97);                 // null
if (!in.isValid()) {
    // this will execute!
}

Builds

Projects using buffero:

Dependencies

Testing Examples