Author: kiwiwings
Date: Mon Mar 21 23:29:06 2016
New Revision: 1736112

URL: http://svn.apache.org/viewvc?rev=1736112&view=rev
Log:
findbugs fixes - RR_NOT_CHECKED

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java
    poi/trunk/src/java/org/apache/poi/util/IOUtils.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmap16.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java Mon Mar 21 
23:29:06 2016
@@ -33,12 +33,13 @@ import org.apache.poi.poifs.filesystem.N
 import org.apache.poi.poifs.filesystem.NPOIFSStream;
 import org.apache.poi.poifs.property.NPropertyTable;
 import org.apache.poi.poifs.storage.HeaderBlock;
+import org.apache.poi.util.IOUtils;
 
 /**
  * Dump internal structure of a OLE2 file into file system
  */
 public class POIFSDump {
-    public static void main(String[] args) throws Exception {
+    public static void main(String[] args) throws IOException {
         if (args.length == 0) {
             System.err.println("Must specify at least one file to dump");
             System.exit(1);
@@ -84,6 +85,8 @@ public class POIFSDump {
                     dump(fs, startBlock, "mini-stream", file);
                 }
             }
+            
+            fs.close();
         }
     }
     
@@ -93,8 +96,7 @@ public class POIFSDump {
             if(entry instanceof DocumentNode){
                 DocumentNode node = (DocumentNode)entry;
                 DocumentInputStream is = new DocumentInputStream(node);
-                byte[] bytes = new byte[node.getSize()];
-                is.read(bytes);
+                byte[] bytes = IOUtils.toByteArray(is);
                 is.close();
 
                 OutputStream out = new FileOutputStream(new File(parent, 
node.getName().trim()));

Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Mon Mar 21 23:29:06 2016
@@ -69,20 +69,33 @@ public final class IOUtils {
      * Reads all the data from the input stream, and returns the bytes read.
      */
     public static byte[] toByteArray(InputStream stream) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        return toByteArray(stream, Integer.MAX_VALUE);
+    }
+
+    /**
+     * Reads up to {@code length} bytes from the input stream, and returns the 
bytes read.
+     */
+    public static byte[] toByteArray(InputStream stream, int length) throws 
IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(length == 
Integer.MAX_VALUE ? 4096 : length);
 
         byte[] buffer = new byte[4096];
-        int read = 0;
-        while (read != -1) {
-            read = stream.read(buffer);
-            if (read > 0) {
-                baos.write(buffer, 0, read);
+        int totalBytes = 0, readBytes = 0; 
+        do {
+            readBytes = stream.read(buffer, 0, Math.min(buffer.length, 
length-totalBytes)); 
+            totalBytes += Math.max(readBytes,0);
+            if (readBytes > 0) {
+                baos.write(buffer, 0, readBytes);
             }
-        }
+        } while (totalBytes < length && readBytes > -1);
 
+        if (length != Integer.MAX_VALUE && totalBytes < length) {
+            throw new IOException("unexpected EOF");
+        }
+        
         return baos.toByteArray();
     }
 
+    
     /**
      * Returns an array (that shouldn't be written to!) of the
      *  ByteBuffer. Will be of the requested length, or possibly

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java Mon Mar 
21 23:29:06 2016
@@ -19,6 +19,7 @@ package org.apache.poi.hdgf;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.poi.POIDocument;
@@ -30,9 +31,9 @@ import org.apache.poi.hdgf.streams.Strea
 import org.apache.poi.hdgf.streams.StringsStream;
 import org.apache.poi.hdgf.streams.TrailerStream;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LocaleUtil;
 
@@ -73,12 +74,10 @@ public final class HDGFDiagram extends P
        public HDGFDiagram(DirectoryNode dir) throws IOException {
                super(dir);
 
-               DocumentEntry docProps =
-                       (DocumentEntry)dir.getEntry("VisioDocument");
-
                // Grab the document stream
-               _docstream = new byte[docProps.getSize()];
-               dir.createDocumentInputStream("VisioDocument").read(_docstream);
+               InputStream is = dir.createDocumentInputStream("VisioDocument");
+               _docstream = IOUtils.toByteArray(is);
+               is.close();
 
                // Check it's really visio
                String typeString = new String(_docstream, 0, 20, 
LocaleUtil.CHARSET_1252 );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java Mon 
Mar 21 23:29:06 2016
@@ -24,8 +24,8 @@ import java.io.InputStream;
 import org.apache.poi.ddf.DefaultEscherRecordFactory;
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.StringUtil;
@@ -47,12 +47,10 @@ public final class HPBFDumper {
        }
 
        private static byte[] getData(DirectoryNode dir, String name) throws 
IOException {
-               DocumentEntry docProps =
-                       (DocumentEntry)dir.getEntry(name);
-
                // Grab the document stream
-               byte[] d = new byte[docProps.getSize()];
-               dir.createDocumentInputStream(name).read(d);
+               InputStream is = dir.createDocumentInputStream(name);
+               byte[] d = IOUtils.toByteArray(is);
+               is.close();
 
                // All done
                return d;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java Mon 
Mar 21 23:29:06 2016
@@ -20,9 +20,10 @@ package org.apache.poi.hpbf.model;
 import java.io.ByteArrayInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
+import org.apache.poi.util.IOUtils;
 
 /**
  * Parent class of all HPBF sub-parts, handling
@@ -39,17 +40,14 @@ public abstract class HPBFPart {
                DirectoryNode dir = getDir(path, baseDir);
                String name = path[path.length-1];
 
-               DocumentEntry docProps;
-               try {
-                       docProps = (DocumentEntry)dir.getEntry(name);
-               } catch (FileNotFoundException e) {
-                       throw new IllegalArgumentException("File invalid - 
failed to find document entry '"
-                                       + name + "'");
+               if (!dir.hasEntry(name)) {
+            throw new IllegalArgumentException("File invalid - failed to find 
document entry '" + name + "'");
                }
 
                // Grab the data from the part stream
-               data = new byte[docProps.getSize()];
-               dir.createDocumentInputStream(name).read(data);
+               InputStream is = dir.createDocumentInputStream(name);
+               data = IOUtils.toByteArray(is);
+               is.close();
        }
        private DirectoryNode getDir(String[] path, DirectoryNode baseDir) {
                DirectoryNode dir = baseDir;

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java 
Mon Mar 21 23:29:06 2016
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.dev;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.Locale;
 
@@ -28,9 +29,9 @@ import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.ddf.EscherTextboxRecord;
 import org.apache.poi.hslf.record.HSLFEscherRecordFactory;
 import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -94,13 +95,10 @@ public final class SlideShowDumper {
    * @throws IOException if there is a problem while parsing the document.
    */
   public SlideShowDumper(NPOIFSFileSystem filesystem, PrintStream out) throws 
IOException {
-       // Get the main document stream
-       DocumentEntry docProps =
-               (DocumentEntry)filesystem.getRoot().getEntry("PowerPoint 
Document");
-
        // Grab the document stream
-       docstream = new byte[docProps.getSize()];
-       filesystem.createDocumentInputStream("PowerPoint 
Document").read(docstream);
+       InputStream is = filesystem.createDocumentInputStream("PowerPoint 
Document");
+       docstream = IOUtils.toByteArray(is);
+       is.close();
        this.out = out;
   }
 

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
 Mon Mar 21 23:29:06 2016
@@ -17,18 +17,20 @@
 
 package org.apache.poi.hslf.extractor;
 
-import java.io.*;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.record.CString;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordTypes;
+import org.apache.poi.hslf.record.TextBytesAtom;
+import org.apache.poi.hslf.record.TextCharsAtom;
 import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
-import org.apache.poi.hslf.usermodel.HSLFTextShape;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -77,7 +79,8 @@ public final class QuickButCruddyTextExt
         * Creates an extractor from a given file name
         * @param fileName
         */
-       public QuickButCruddyTextExtractor(String fileName) throws IOException {
+       @SuppressWarnings("resource")
+    public QuickButCruddyTextExtractor(String fileName) throws IOException {
                this(new NPOIFSFileSystem(new File(fileName)));
        }
 
@@ -85,6 +88,7 @@ public final class QuickButCruddyTextExt
         * Creates an extractor from a given input stream
         * @param iStream
         */
+    @SuppressWarnings("resource")
        public QuickButCruddyTextExtractor(InputStream iStream) throws 
IOException {
                this(new NPOIFSFileSystem(iStream));
                is = iStream;
@@ -98,10 +102,9 @@ public final class QuickButCruddyTextExt
                fs = poifs;
 
                // Find the PowerPoint bit, and get out the bytes
-               DocumentEntry docProps =
-                       (DocumentEntry)fs.getRoot().getEntry("PowerPoint 
Document");
-               pptContents = new byte[docProps.getSize()];
-               fs.createDocumentInputStream("PowerPoint 
Document").read(pptContents);
+               InputStream pptIs = fs.createDocumentInputStream("PowerPoint 
Document");
+               pptContents = IOUtils.toByteArray(pptIs);
+               pptIs.close();
        }
 
 

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmap16.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmap16.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmap16.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmap16.java 
Mon Mar 21 23:29:06 2016
@@ -20,6 +20,7 @@ package org.apache.poi.hwmf.record;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
@@ -72,9 +73,9 @@ public class HwmfBitmap16 {
             size += 18+LittleEndianConsts.INT_SIZE;
         }
 
-        int bytes = (((width * bitsPixel + 15) >> 4) << 1) * height;
-        byte buf[] = new byte[bytes];
-        leis.read(buf);
+        int length = (((width * bitsPixel + 15) >> 4) << 1) * height;
+        @SuppressWarnings("unused")
+        byte buf[] = IOUtils.toByteArray(leis, length);
         
         // TODO: this is not implemented ... please provide a sample, if it
         // ever happens to you, to come here ...

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfBitmapDib.java 
Mon Mar 21 23:29:06 2016
@@ -26,12 +26,13 @@ import java.io.InputStream;
 
 import javax.imageio.ImageIO;
 
-import org.apache.poi.hssf.record.RecordFormatException;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.RecordFormatException;
 
 /**
  * The DeviceIndependentBitmap Object defines an image in device-independent 
bitmap (DIB) format.
@@ -224,9 +225,8 @@ public class HwmfBitmapDib {
 
         int fileSize = (headerImageSize < headerSize) ? recordSize : 
(int)Math.min(introSize+headerImageSize,recordSize);
         
-        imageData = new byte[fileSize];
         leis.reset();
-        leis.read(imageData, 0, fileSize);
+        imageData = IOUtils.toByteArray(leis, fileSize);
         
         assert( headerSize != 0x0C || ((((headerWidth * headerPlanes * 
headerBitCount.flag + 31) & ~31) / 8) * Math.abs(headerHeight)) == 
headerImageSize);
 

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java Mon 
Mar 21 23:29:06 2016
@@ -21,6 +21,7 @@ import java.io.IOException;
 
 import org.apache.poi.hwmf.draw.HwmfGraphics;
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
@@ -192,8 +193,8 @@ public class HwmfEscape implements HwmfR
     public int init(LittleEndianInputStream leis, long recordSize, int 
recordFunction) throws IOException {
         escapeFunction = EscapeFunction.valueOf(leis.readUShort());
         byteCount = leis.readUShort();
-        escapeData = new byte[byteCount];
-        leis.read(escapeData);
+        escapeData = IOUtils.toByteArray(leis,byteCount);
+
         return 2*LittleEndianConsts.SHORT_SIZE+byteCount;
     }
 

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfPlaceableHeader.java
 Mon Mar 21 23:29:06 2016
@@ -45,7 +45,7 @@ public class HwmfPlaceableHeader {
         int y1 = leis.readShort();
         int x2 = leis.readShort();
         int y2 = leis.readShort();
-        bounds = new Rectangle2D.Double(x1, y1, x2-x1, y2-y1);
+        bounds = new Rectangle2D.Double(Math.min(x1,x2), Math.min(y1,y2), 
Math.abs(x2-x1), Math.abs(y2-y1));
         
         /*
          * Inch (2 bytes):  The number of logical units per inch used to 
represent the image.

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Mon Mar 
21 23:29:06 2016
@@ -18,7 +18,6 @@
 package org.apache.poi.hwpf;
 
 import java.io.ByteArrayInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -69,6 +68,7 @@ import org.apache.poi.poifs.filesystem.E
 import org.apache.poi.poifs.filesystem.EntryUtils;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Internal;
 
 /**
@@ -230,17 +230,14 @@ public final class HWPFDocument extends
     }
 
     // Grab the table stream.
-    DocumentEntry tableProps;
-    try {
-        tableProps =
-            (DocumentEntry)directory.getEntry(name);
-    } catch(FileNotFoundException fnfe) {
+    if (!directory.hasEntry(name)) {
         throw new IllegalStateException("Table Stream '" + name + "' wasn't 
found - Either the document is corrupt, or is Word95 (or earlier)");
     }
 
     // read in the table stream.
-    _tableStream = new byte[tableProps.getSize()];
-    directory.createDocumentInputStream(name).read(_tableStream);
+    InputStream is = directory.createDocumentInputStream(name);
+    _tableStream = IOUtils.toByteArray(is);
+    is.close();
 
     _fib.fillVariableFields(_mainStream, _tableStream);
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java?rev=1736112&r1=1736111&r2=1736112&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java Mon 
Mar 21 23:29:06 2016
@@ -38,6 +38,7 @@ import org.apache.poi.poifs.filesystem.D
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Internal;
 
 
@@ -85,14 +86,13 @@ public abstract class HWPFDocumentCore e
   }
 
   /**
-   * Takens an InputStream, verifies that it's not RTF or PDF, builds a
+   * Takes an InputStream, verifies that it's not RTF or PDF, builds a
    *  POIFSFileSystem from it, and returns that.
    */
   public static POIFSFileSystem verifyAndBuildPOIFS(InputStream istream) 
throws IOException {
        // Open a PushbackInputStream, so we can peek at the first few bytes
        PushbackInputStream pis = new PushbackInputStream(istream,6);
-       byte[] first6 = new byte[6];
-       pis.read(first6);
+       byte[] first6 = IOUtils.toByteArray(pis, 6);
 
        // Does it start with {\rtf ? If so, it's really RTF
        if(first6[0] == '{' && first6[1] == '\\' && first6[2] == 'r'



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

Reply via email to