Ignore:
Timestamp:
02/21/11 09:51:41 (15 months ago)
Author:
jharrop
Message:

Patch contributed by Alberto. Re the implementation prior to this patch:
"If the part/file is less than 1024 bytes then the capacity of the ByteBuffer? is 1024 (and clear() sets the limit to the capacity). This means, that the file written will be padded
with zero-bytes. In most cases this doesn't matter, but I noticed it while doing the altChunk stuff with a small text-file. In this case, winword will show some garbage after the text. "

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/io/SaveToZipFile.java

    r1379 r1430  
    386386                String resolvedPartUri = part.getPartName().getName().substring(1); 
    387387 
    388                 //InputStream bin = ((BinaryPart)part).getBinaryData();          
    389  
    390388                try { 
    391389                // Add ZIP entry to output stream. 
    392390                out.putNextEntry(new ZipEntry(resolvedPartUri)); 
    393                          
    394                         // Copy the input stream to the output stream 
    395 //                      byte[] buffer = new byte[8192]; 
    396 //                      int amount; 
    397 //                      while (( amount = bin.read(buffer)) >=0 ) { 
    398 //                              log.debug(amount); 
    399 //                              out.write(buffer, 0, amount);                    
    400 //                      } 
     391                                 
     392            java.nio.ByteBuffer bb = ((BinaryPart)part).getBuffer(); 
     393            byte[] bytes = null; 
     394            bytes = new byte[bb.limit()]; 
     395            bb.get(bytes);               
    401396                 
    402                 java.nio.ByteBuffer bb = ((BinaryPart)part).getBuffer(); 
    403                 bb.clear(); 
    404                 byte[] bytes = new byte[bb.capacity()]; 
    405                 bb.get(bytes, 0, bytes.length); 
    406                                  
    407397                out.write( bytes ); 
    408398 
Note: See TracChangeset for help on using the changeset viewer.