Author: fanningpj
Date: Tue Oct 17 13:42:33 2023
New Revision: 1913062

URL: http://svn.apache.org/viewvc?rev=1913062&view=rev
Log:
[XMLBEANS-474] try to support writing larger XML output

Modified:
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java
URL: 
http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java?rev=1913062&r1=1913061&r2=1913062&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java 
(original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java Tue 
Oct 17 13:42:33 2023
@@ -2234,6 +2234,10 @@ abstract class Saver {
     }
 
     static final class InputStreamSaver extends InputStream {
+
+        // this is based on what is used in the core Java classes
+        private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
+
         InputStreamSaver(Cur c, XmlOptions options) {
             _locale = c._locale;
 
@@ -2477,14 +2481,16 @@ abstract class Saver {
             void resize(int cbyte) {
                 assert cbyte > _free : cbyte + " !> " + _free;
 
-                int newLen = _buf == null ? _initialBufSize : _buf.length * 2;
+                long newLen = _buf == null ? _initialBufSize : _buf.length * 2;
                 int used = getAvailable();
 
                 while (newLen - used < cbyte) {
                     newLen *= 2;
                 }
 
-                byte[] newBuf = new byte[newLen];
+                final int bufLen = (int) Math.min(newLen, MAX_ARRAY_SIZE);
+
+                final byte[] newBuf = new byte[bufLen];
 
                 if (used > 0) {
                     if (_in > _out) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to