Changeset 1093


Ignore:
Timestamp:
02/27/10 17:44:08 (2 years ago)
Author:
jharrop
Message:

changes to exception handling; made class ByteArray? a bit more flexible

File:
1 edited

Legend:

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

    r1078 r1093  
    3333import java.net.URI; 
    3434import java.net.URISyntaxException; 
     35import java.nio.ByteBuffer; 
    3536import java.util.Enumeration; 
    3637import java.util.HashMap; 
     
    6162 
    6263 
    63  
    6464/** 
    6565 * Create a Package object from a Zip file or input stream. 
     
    171171        } catch (Exception e) { 
    172172            log.error(e.getMessage()); 
     173            throw new Docx4JException("Error processing zip file (is it a zip file?)", e); 
    173174        }        
    174                  
     175                     
    175176                // At this point, we're finished with the zip input stream 
    176177        // TODO, so many of the below methods could be renamed. 
     
    289290                        String partName)  
    290291        //private static InputStream getInputStreamFromZippedPart(ZipFile zf, String partName)  
    291                 throws IOException { 
     292                throws IOException, NullPointerException { 
    292293                 
    293294                InputStream in = null; 
    294295                //in = zf.getInputStream( zf.getEntry(partName ) ); 
    295                 in = partByteArrays.get(partName).getInputStream(); 
     296                try { 
     297                        in = partByteArrays.get(partName).getInputStream(); 
     298                } catch (NullPointerException  npe) { 
     299                        log.warn("Part " + partName + " was null"); 
     300                        throw npe; 
     301                } 
    296302                return in;               
    297303        } 
     
    554560                                // Try to get it as a binary part 
    555561                                part = getBinaryPart(partByteArrays, ctm, resolvedPartUri); 
     562                                log.warn("Using BinaryPart for " + resolvedPartUri); 
     563                                 
    556564                                ((BinaryPart)part).setBinaryData(is); 
    557565                        } 
     
    609617        public static class ByteArray implements Serializable { 
    610618                 
     619                private static final long serialVersionUID = -784146312250361899L; 
     620                // 4469266984448028582L;  
     621                 
    611622                private byte[] bytes; 
     623                public byte[] getBytes() { 
     624                        return bytes; 
     625                } 
     626 
     627                private String mimetype; 
     628                public String getMimetype() { 
     629                        return mimetype;                         
     630                } 
    612631                 
    613632                public ByteArray(byte[] bytes) { 
     
    616635                } 
    617636                 
     637                 
     638                public ByteArray(ByteBuffer bb, String mimetype ) { 
     639                         
     640                        bb.clear(); 
     641                        bytes = new byte[bb.capacity()]; 
     642                        bb.get(bytes, 0, bytes.length); 
     643                         
     644                        this.mimetype = mimetype; 
     645                } 
     646                 
     647                 
    618648                public InputStream getInputStream() { 
    619                          
    620649                        return new ByteArrayInputStream(bytes); 
    621                          
     650                } 
     651 
     652                public int getLength() { 
     653                        return bytes.length;                     
    622654                } 
    623655                 
Note: See TracChangeset for help on using the changeset viewer.