/// <summary> /// Appends <code>len</code> chars to this buffer from the given source /// char array buffer starting at index <code>off</code>. /// </summary> /// <remarks> /// Appends <code>len</code> chars to this buffer from the given source /// char array buffer starting at index <code>off</code>. The capacity /// of the buffer is increased if necessary to accommodate all /// <code>len</code> chars. /// <p> /// The chars are converted to bytes using simple cast. /// </remarks> /// <param name="b">the chars to be appended.</param> /// <param name="off">the index of the first char to append.</param> /// <param name="len">the number of bytes to append.</param> /// <exception cref="System.IndexOutOfRangeException"> /// if <code>off</code> if out of /// range, <code>len</code> is negative, or /// <code>off</code> + <code>len</code> is out of range. /// </exception> public void Append(CharArrayBuffer b, int off, int len) { if (b == null) { return; } Append(b.Buffer(), off, len); }
/// <summary> /// Appends all chars to this buffer from the given source buffer starting /// at index <code>0</code>. /// </summary> /// <remarks> /// Appends all chars to this buffer from the given source buffer starting /// at index <code>0</code>. The capacity of the destination buffer is /// increased, if necessary, to accommodate all /// <see cref="Length()">Length()</see> /// chars. /// </remarks> /// <param name="b">the source buffer to be appended.</param> public void Append(Org.Apache.Http.Util.CharArrayBuffer b) { if (b == null) { return; } Append(b.buffer, 0, b.len); }
/// <summary> /// Appends <code>len</code> chars to this buffer from the given source /// buffer starting at index <code>off</code>. /// </summary> /// <remarks> /// Appends <code>len</code> chars to this buffer from the given source /// buffer starting at index <code>off</code>. The capacity of the /// destination buffer is increased, if necessary, to accommodate all /// <code>len</code> chars. /// </remarks> /// <param name="b">the source buffer to be appended.</param> /// <param name="off">the index of the first char to append.</param> /// <param name="len">the number of chars to append.</param> /// <exception cref="System.IndexOutOfRangeException"> /// if <code>off</code> is out of /// range, <code>len</code> is negative, or /// <code>off</code> + <code>len</code> is out of range. /// </exception> public void Append(Org.Apache.Http.Util.CharArrayBuffer b, int off, int len) { if (b == null) { return; } Append(b.buffer, off, len); }
/// <summary> /// Get the entity content as a String, using the provided default character set /// if none is found in the entity. /// </summary> /// <remarks> /// Get the entity content as a String, using the provided default character set /// if none is found in the entity. /// If defaultCharset is null, the default "ISO-8859-1" is used. /// </remarks> /// <param name="entity">must not be null</param> /// <param name="defaultCharset">character set to be applied if none found in the entity /// </param> /// <returns> /// the entity content as a String. May be null if /// <see cref="Org.Apache.Http.HttpEntity.GetContent()">Org.Apache.Http.HttpEntity.GetContent() /// </see> /// is null. /// </returns> /// <exception cref="Org.Apache.Http.ParseException">if header elements cannot be parsed /// </exception> /// <exception cref="System.ArgumentException">if entity is null or if content length > Integer.MAX_VALUE /// </exception> /// <exception cref="System.IO.IOException">if an error occurs reading the input stream /// </exception> /// <exception cref="Sharpen.UnsupportedCharsetException"> /// Thrown when the named charset is not available in /// this instance of the Java virtual machine /// </exception> public static string ToString(HttpEntity entity, Encoding defaultCharset) { Args.NotNull(entity, "Entity"); InputStream instream = entity.GetContent(); if (instream == null) { return(null); } try { Args.Check(entity.GetContentLength() <= int.MaxValue, "HTTP entity too large to be buffered in memory" ); int i = (int)entity.GetContentLength(); if (i < 0) { i = 4096; } Encoding charset = null; try { ContentType contentType = ContentType.Get(entity); if (contentType != null) { charset = contentType.GetCharset(); } } catch (UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.Message); } if (charset == null) { charset = defaultCharset; } if (charset == null) { charset = HTTP.DefContentCharset; } StreamReader reader = new InputStreamReader(instream, charset); CharArrayBuffer buffer = new CharArrayBuffer(i); char[] tmp = new char[1024]; int l; while ((l = reader.Read(tmp)) != -1) { buffer.Append(tmp, 0, l); } return(buffer.ToString()); } finally { instream.Close(); } }