2008-04-23 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web / HttpWriter.cs
index 9fb607c2a19b844f43952660516ebd22d17060b5..4b608d16ef7f78c6eb2b6a38154173be56ecee28 100644 (file)
@@ -119,11 +119,14 @@ namespace System.Web {
                {
                        if (buffer == null || index < 0 || count < 0 || (buffer.Length - index) < count)
                                throw new ArgumentOutOfRangeException ();
-                       
-                       int length = encoding.GetByteCount (buffer, index, count);
+#if TARGET_JVM
+                       output_stream.Write (buffer, index, count);
+#else
+                       int length = encoding.GetMaxByteCount (count);
                        byte [] bytebuffer = GetByteBuffer (length);
-                       encoding.GetBytes (buffer, index, count, bytebuffer, 0);
-                       output_stream.Write (bytebuffer, 0, length);
+                       int realLength = encoding.GetBytes (buffer, index, count, bytebuffer, 0);
+                       output_stream.Write (bytebuffer, 0, realLength);
+#endif
                        if (response.buffer)
                                return;
 
@@ -144,18 +147,14 @@ namespace System.Web {
 
                        if (index < 0 || count < 0 || ((index + count > s.Length)))
                                throw new ArgumentOutOfRangeException ();
-                       
-                       int length;
-                       if (index == 0 && count == s.Length) {
-                               length = encoding.GetByteCount (s); 
-                       } else {
-                               char [] chars = s.ToCharArray (index, count);
-                               length = encoding.GetByteCount (chars);
-                       }
-
+#if TARGET_JVM
+                       output_stream.Write (s, index, count);
+#else
+                       int length = encoding.GetMaxByteCount (count);
                        byte [] bytebuffer = GetByteBuffer (length);
-                       encoding.GetBytes (s, index, count, bytebuffer, 0);
-                       output_stream.Write (bytebuffer, 0, length);
+                       int realLength = encoding.GetBytes (s, index, count, bytebuffer, 0);
+                       output_stream.Write (bytebuffer, 0, realLength);
+#endif
                        if (response.buffer)
                                return;