public Buffer(ByteBuffer.ByteOrder order) { b = _emptyBuffer; _size = 0; _capacity = 0; _order = order; }
public Buffer(int maxCapacity) { b = _emptyBuffer; _size = 0; _capacity = 0; _maxCapacity = maxCapacity; }
public Buffer(ByteBuffer data, ByteBuffer.ByteOrder order) { b = data; b.order(order); _size = data.remaining(); _capacity = 0; _order = order; }
public Buffer(byte[] data, ByteBuffer.ByteOrder order) { b = ByteBuffer.wrap(data); b.order(order); _size = data.Length; _capacity = 0; _order = order; }
public Buffer(Buffer buf, bool adopt) { b = buf.b; _size = buf._size; _capacity = buf._capacity; _shrinkCounter = buf._shrinkCounter; _order = buf._order; if(adopt) { buf.clear(); } }
public void clear() { b = _emptyBuffer; _size = 0; _capacity = 0; _shrinkCounter = 0; }
public Buffer(ByteBuffer data) : this(data, ByteBuffer.ByteOrder.LITTLE_ENDIAN) { }
private void reserve(int n) { Debug.Assert(_capacity == b.capacity()); if(n > _capacity) { _capacity = System.Math.Max(n, 2 * _capacity); _capacity = System.Math.Max(240, _capacity); } else if(n < _capacity) { _capacity = n; } else { return; } try { ByteBuffer buf = ByteBuffer.allocate(_capacity); if(b == _emptyBuffer) { b = buf; } else { int pos = b.position(); b.position(0); b.limit(System.Math.Min(_capacity, b.capacity())); buf.put(b); b = buf; b.limit(b.capacity()); b.position(pos); } b.order(_order); } catch(System.OutOfMemoryException) { _capacity = b.capacity(); // Restore the previous capacity throw; } catch(System.Exception ex) { _capacity = b.capacity(); // Restore the previous capacity. Ice.MarshalException e = new Ice.MarshalException(ex); e.reason = "unexpected exception while trying to allocate a ByteBuffer:\n" + ex; throw e; } finally { Debug.Assert(_capacity == b.capacity()); } }
public void clear() { b = _emptyBuffer; _size = 0; _capacity = 0; }