Hi,

when writing large chunks of data over UNC paths (SMB shares) on Windows 
it may happen that an errnous exception ("insufficient system 
ressources") is thrown. Actually, the problem seems to be that the 
underlying Windows subsystem fails when one uses OutputStream#write() on 
buffers larger than 64 MB when the stream points to a file on the 
network on Windows. See for example this forum thread for more info:

http://forums.sun.com/thread.jspa?threadID=5270971

For us, this happened when embedding large PDFs into even larger PDFs on 
a network drive with iText. The patch below was developed as a 
"quick-and-dirty" solution to the problem. In theory, writing data in 1 
MB chunks may lead to slightly degraded performance, however, in the 
real world this effect should be neglectible for such large blocks.

I am posting this here for discussion. We do know that a more complete 
and elegant solution may exist and would be grateful for suggestions. In 
the end, we would welcome when a fix for this issue would find the way 
into the main iText distribution so we do not have to maintain separate 
patches.

Markus


--- 
itext_orig\src\core\com\itextpdf\text\pdf\OutputStreamCounter.java    
2010-01-27 22:24:09.974291300 +0100
+++ itext\src\core\com\itextpdf\text\pdf\OutputStreamCounter.java    
2010-01-28 19:34:08.583642600 +0100
@@ -100,8 +100,7 @@
       *
       */
      public void write(byte[] b) throws IOException {
-        counter += b.length;
-        out.write(b);
+        write(b, 0, b.length);
      }

      /** Writes the specified byte to this output stream. The general
@@ -154,7 +153,17 @@
       */
      public void write(byte[] b, int off, int len) throws IOException {
          counter += len;
-        out.write(b, off, len);
+
+        // On some Windows systems, writing large amounts of bytes at once
+        // using os.write() fails when using UNC paths, so we write data in
+        // 1 MB chunks instead. Actually, we could go as high as about 
64 MB
+        // until Windows fails. See for example this page for information:
+        //     http://forums.sun.com/thread.jspa?threadID=5270971
+        final int BUFSIZE = 1024 * 1024;
+        for (int cur = off; cur < off + len; cur += BUFSIZE) {
+            out.write(b, cur, Math.min(BUFSIZE, off + len - cur));
+            out.flush();
+        }
      }

      public int getCounter() {


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to