1 2 17 18 19 package org.apache.poi.poifs.storage; 20 21 import java.io.*; 22 23 import java.util.*; 24 25 import org.apache.poi.poifs.common.POIFSConstants; 26 import org.apache.poi.poifs.property.Property; 27 import org.apache.poi.util.IntegerField; 28 import org.apache.poi.util.LittleEndian; 29 import org.apache.poi.util.LittleEndianConsts; 30 31 36 37 public class PropertyBlock 38 extends BigBlock 39 { 40 private static final int _properties_per_block = 41 POIFSConstants.BIG_BLOCK_SIZE / POIFSConstants.PROPERTY_SIZE; 42 private Property[] _properties; 43 44 50 51 private PropertyBlock(final Property [] properties, final int offset) 52 { 53 _properties = new Property[ _properties_per_block ]; 54 for (int j = 0; j < _properties_per_block; j++) 55 { 56 _properties[ j ] = properties[ j + offset ]; 57 } 58 } 59 60 70 71 public static BlockWritable [] createPropertyBlockArray( 72 final List properties) 73 { 74 int block_count = 75 (properties.size() + _properties_per_block - 1) 76 / _properties_per_block; 77 Property[] to_be_written = 78 new Property[ block_count * _properties_per_block ]; 79 80 System.arraycopy(properties.toArray(new Property[ 0 ]), 0, 81 to_be_written, 0, properties.size()); 82 for (int j = properties.size(); j < to_be_written.length; j++) 83 { 84 85 to_be_written[ j ] = new Property() 88 { 89 protected void preWrite() 90 { 91 } 92 93 public boolean isDirectory() 94 { 95 return false; 96 } 97 }; 98 } 99 BlockWritable[] rvalue = new BlockWritable[ block_count ]; 100 101 for (int j = 0; j < block_count; j++) 102 { 103 rvalue[ j ] = new PropertyBlock(to_be_written, 104 j * _properties_per_block); 105 } 106 return rvalue; 107 } 108 109 110 111 120 121 void writeData(final OutputStream stream) 122 throws IOException 123 { 124 for (int j = 0; j < _properties_per_block; j++) 125 { 126 _properties[ j ].writeData(stream); 127 } 128 } 129 130 131 } 133 | Popular Tags |