1 2 17 18 19 package org.apache.poi.poifs.storage; 20 21 import java.io.*; 22 23 import java.util.*; 24 25 30 31 class BlockListImpl 32 implements BlockList 33 { 34 private ListManagedBlock[] _blocks; 35 private BlockAllocationTableReader _bat; 36 37 40 41 protected BlockListImpl() 42 { 43 _blocks = new ListManagedBlock[ 0 ]; 44 _bat = null; 45 } 46 47 52 53 protected void setBlocks(final ListManagedBlock [] blocks) 54 { 55 _blocks = blocks; 56 } 57 58 59 60 66 67 public void zap(final int index) 68 { 69 if ((index >= 0) && (index < _blocks.length)) 70 { 71 _blocks[ index ] = null; 72 } 73 } 74 75 85 86 public ListManagedBlock remove(final int index) 87 throws IOException 88 { 89 ListManagedBlock result = null; 90 91 try 92 { 93 result = _blocks[ index ]; 94 if (result == null) 95 { 96 throw new IOException("block[ " + index 97 + " ] already removed"); 98 } 99 _blocks[ index ] = null; 100 } 101 catch (ArrayIndexOutOfBoundsException ignored) 102 { 103 throw new IOException("Cannot remove block[ " + index 104 + " ]; out of range"); 105 } 106 return result; 107 } 108 109 119 120 public ListManagedBlock [] fetchBlocks(final int startBlock) 121 throws IOException 122 { 123 if (_bat == null) 124 { 125 throw new IOException( 126 "Improperly initialized list: no block allocation table provided"); 127 } 128 return _bat.fetchBlocks(startBlock, this); 129 } 130 131 138 139 public void setBAT(final BlockAllocationTableReader bat) 140 throws IOException 141 { 142 if (_bat != null) 143 { 144 throw new IOException( 145 "Attempt to replace existing BlockAllocationTable"); 146 } 147 _bat = bat; 148 } 149 150 151 } 153 | Popular Tags |