1 2 17 18 19 package org.apache.poi.poifs.storage; 20 21 import org.apache.poi.poifs.common.POIFSConstants; 22 import org.apache.poi.util.IOUtils; 23 24 import java.io.*; 25 26 31 32 public class RawDataBlock 33 implements ListManagedBlock 34 { 35 private byte[] _data; 36 private boolean _eof; 37 38 46 47 public RawDataBlock(final InputStream stream) 48 throws IOException 49 { 50 _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ]; 51 int count = IOUtils.readFully(stream, _data); 52 53 if (count == -1) 54 { 55 _eof = true; 56 } 57 else if (count != POIFSConstants.BIG_BLOCK_SIZE) 58 { 59 String type = " byte" + ((count == 1) ? ("") 60 : ("s")); 61 62 throw new IOException("Unable to read entire block; " + count 63 + type + " read; expected " 64 + POIFSConstants.BIG_BLOCK_SIZE + " bytes"); 65 } 66 else 67 { 68 _eof = false; 69 } 70 } 71 72 80 81 public boolean eof() 82 throws IOException 83 { 84 return _eof; 85 } 86 87 88 89 96 97 public byte [] getData() 98 throws IOException 99 { 100 if (eof()) 101 { 102 throw new IOException("Cannot return empty data"); 103 } 104 return _data; 105 } 106 107 108 } 110 | Popular Tags |