/// <summary> /// Create a new Blob from an existing ByteBuffer. IMPORTANT: If copy is /// false, after calling this constructor, if you keep a pointer to the buffer /// then you must treat it as immutable and promise not to change it. /// </summary> /// /// <param name="buffer"></param> /// <param name="copy"></param> public Blob(ByteBuffer buffer, bool copy) { this.haveHashCode_ = false; if (buffer != null) { if (copy) { buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(buffer.remaining()); // Put updates buffer.position(), so save and restore it. int savePosition = buffer.position(); buffer_.put(buffer); buffer.position(savePosition); buffer_.flip(); } else buffer_ = buffer.slice(); } else buffer_ = null; }
/// <summary> /// Create a new Blob from the UTF-8 encoding of the Unicode string. /// </summary> /// /// <param name="value">The Unicode string which is encoded as UTF-8.</param> public Blob(String value_ren) { this.haveHashCode_ = false; byte[] utf8; try { utf8 = ILOG.J2CsMapping.Util.StringUtil.GetBytes(value_ren,"UTF-8"); } catch (IOException ex) { // We don't expect this to happen. throw new Exception("UTF-8 encoder not supported: " + ex.Message); } buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(utf8.Length); buffer_.put(utf8); buffer_.flip(); }
/// <summary> /// Create a new Blob with a copy of the bytes in the array. /// </summary> /// /// <param name="value">The byte array to copy.</param> public Blob(byte[] value_ren) { this.haveHashCode_ = false; buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(value_ren.Length); buffer_.put(value_ren); buffer_.flip(); }
/// <summary> /// Create a new Blob with a copy of the bytes in the array. /// </summary> /// /// <param name="value"></param> public Blob(int[] value_ren) { this.haveHashCode_ = false; buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(value_ren.Length); for (int i = 0; i < value_ren.Length; ++i) buffer_.put((byte) value_ren[i]); buffer_.flip(); }
/// <summary> /// Create a new Blob from the the byte array. IMPORTANT: If copy is false, /// after calling this constructor, if you keep a pointer to the buffer then /// you must treat it as immutable and promise not to change it. /// </summary> /// /// <param name="value">The byte array. If copy is true, this makes a copy.</param> /// <param name="copy"></param> public Blob(byte[] value_ren, bool copy) { this.haveHashCode_ = false; if (copy) { buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(value_ren.Length); buffer_.put(value_ren); buffer_.flip(); } else buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.wrap(value_ren); }