use of de.invesdwin.util.streams.buffer.bytes.IByteBuffer in project invesdwin-context-persistence by subes.
the class SerializingCollection method add.
@Override
public boolean add(final E element) {
if (this.size == READ_ONLY_FILE_SIZE) {
throw new IllegalStateException("File [" + file + "] is in read only mode since it contained data when it was opened!");
}
try {
final IByteBuffer writeBuffer = getWriteBuffer();
final int length = serde.toBuffer(writeBuffer, element);
if (length == 0) {
throw new IllegalStateException("bytes should contain actual data: " + element);
}
final OutputStream fos = getFos();
if (fixedLength == null) {
OutputStreams.writeInt(fos, length);
} else {
if (length != fixedLength) {
throw new IllegalArgumentException("Serialized object [" + element + "] has unexpected byte length of [" + length + "] while fixed length [" + fixedLength + "] was expected!");
}
}
writeBuffer.getBytesTo(0, fos, length);
} catch (final IOException e) {
throw new RuntimeException(e);
}
size++;
return true;
}
Aggregations