Example #1
0
 public virtual Variant Allocate(ByteBuffer value)
 {
     int len = mPool.Count;
     if (len == 0)
     {
         return new Variant(value);
     }
     else
     {
         Variant ret = mPool[len - 1];
         mPool.Remove(len - 1);
         ret.Set(value);
         return ret;
     }
 }
 // end input remaining
 /// <summary>
 /// Performs Base64 encoding on the <code>raw</code> ByteBuffer,
 /// writing it to the <code>encoded</code> CharBuffer.
 /// </summary>
 /// <remarks>
 /// Performs Base64 encoding on the <code>raw</code> ByteBuffer,
 /// writing it to the <code>encoded</code> CharBuffer.
 /// This is an experimental feature. Currently it does not
 /// pass along any options (such as
 /// <see cref="DoBreakLines">DoBreakLines</see>
 /// or
 /// <see cref="Gzip">Gzip</see>
 /// .
 /// </remarks>
 /// <param name="raw">input buffer</param>
 /// <param name="encoded">output buffer</param>
 /// <since>2.3</since>
 public static void Encode(ByteBuffer raw, CharBuffer encoded)
 {
     byte[] raw3 = new byte[3];
     byte[] enc4 = new byte[4];
     while (raw.HasRemaining())
     {
         int rem = Math.Min(3, raw.Remaining());
         raw.Get(raw3, 0, rem);
         Couchbase.Lite.Support.Base64.Encode3to4(enc4, raw3, rem, Couchbase.Lite.Support.Base64
             .NoOptions);
         for (int i = 0; i < 4; i++)
         {
             encoded.Put((char)(enc4[i] & unchecked((int)(0xFF))));
         }
     }
 }
 // end switch
 // end encode3to4
 /// <summary>
 /// Performs Base64 encoding on the <code>raw</code> ByteBuffer,
 /// writing it to the <code>encoded</code> ByteBuffer.
 /// </summary>
 /// <remarks>
 /// Performs Base64 encoding on the <code>raw</code> ByteBuffer,
 /// writing it to the <code>encoded</code> ByteBuffer.
 /// This is an experimental feature. Currently it does not
 /// pass along any options (such as
 /// <see cref="DoBreakLines">DoBreakLines</see>
 /// or
 /// <see cref="Gzip">Gzip</see>
 /// .
 /// </remarks>
 /// <param name="raw">input buffer</param>
 /// <param name="encoded">output buffer</param>
 /// <since>2.3</since>
 public static void Encode(ByteBuffer raw, ByteBuffer encoded)
 {
     byte[] raw3 = new byte[3];
     byte[] enc4 = new byte[4];
     while (raw.HasRemaining())
     {
         int rem = Math.Min(3, raw.Remaining());
         raw.Get(raw3, 0, rem);
         Couchbase.Lite.Support.Base64.Encode3to4(enc4, raw3, rem, Couchbase.Lite.Support.Base64
             .NoOptions);
         encoded.Put(enc4);
     }
 }
Example #4
0
 private int PutByteBuffer(ByteBuffer val)
 {
     int index = mByteBufferHash.Get(val);
     if (index == null)
     {
         index = Sharpen.Extensions.ValueOf(mByteBuffer.Count);
         mByteBuffer.AddItem(val);
         mByteBufferHash.Put(val, index);
         return index;
     }
     else
     {
         return index;
     }
 }
Example #5
0
 // 渡されたByteBufferを切り诘めた、新しいByteBufferを作る
 private ByteBuffer CompactByteBuffer(ByteBuffer b)
 {
     int count = b.Position();
     ByteBuffer ret = ByteBuffer.AllocateDirect(count);
     b.Position(0);
     for (int i = 0; i < count; i++)
     {
         ret.Put(b.Get());
     }
     ret.Position(0);
     return ret;
 }
Example #6
0
 /// <summary>returns actually read size</summary>
 /// <exception cref="TJSException">TJSException</exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public abstract int Read(ByteBuffer buffer);
Example #7
0
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void WriteBuffer(ByteBuffer buffer)
 {
     if (Write(buffer) != -1)
     {
         throw new TJSException(Error.WriteError);
     }
 }
Example #8
0
 /// <summary>returns actually written size</summary>
 public abstract int Write(ByteBuffer buffer);
Example #9
0
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void ReadBuffer(ByteBuffer buffer)
 {
     if (Read(buffer) != -1)
     {
         throw new TJSException(Error.ReadError);
     }
     buffer.Flip();
 }