// 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); } }
// 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)))); } } }
// 渡された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; }