1 19 20 package jxl.demo; 21 22 import java.io.OutputStream ; 23 import java.io.BufferedWriter ; 24 import java.io.OutputStreamWriter ; 25 import java.io.FileInputStream ; 26 import java.io.IOException ; 27 28 import jxl.WorkbookSettings; 29 import jxl.read.biff.CompoundFile; 30 import jxl.read.biff.BiffException; 31 import jxl.biff.BaseCompoundFile; 32 33 36 class PropertySetsReader 37 { 38 private BufferedWriter writer; 39 private CompoundFile compoundFile; 40 41 50 public PropertySetsReader(java.io.File file, String propertySet, 51 OutputStream os) 52 throws IOException , BiffException 53 { 54 writer = new BufferedWriter (new OutputStreamWriter (os)); 55 FileInputStream fis = new FileInputStream (file); 56 57 int initialFileSize = 1024*1024; int arrayGrowSize = 1024*1024; 60 byte[] d = new byte[initialFileSize]; 61 int bytesRead = fis.read(d); 62 int pos = bytesRead; 63 64 while (bytesRead != -1) 65 { 66 if (pos >= d.length) 67 { 68 byte newArray[] = new byte[d.length + arrayGrowSize]; 70 System.arraycopy(d, 0, newArray, 0, d.length); 71 d = newArray; 72 } 73 bytesRead = fis.read(d, pos, d.length - pos); 74 pos += bytesRead; 75 } 76 77 bytesRead = pos + 1; 78 79 compoundFile = new CompoundFile(d, new WorkbookSettings()); 80 fis.close(); 81 82 if (propertySet == null) 83 { 84 displaySets(); 85 } 86 else 87 { 88 displayPropertySet(propertySet, os); 89 } 90 } 91 92 95 void displaySets() throws IOException 96 { 97 String [] sets = compoundFile.getPropertySetNames(); 98 99 for (int i = 0; i < sets.length ; i++) 100 { 101 BaseCompoundFile.PropertyStorage ps = compoundFile.getPropertySet(sets[i]); 102 writer.write(Integer.toString(i)); 103 writer.write(") "); 104 writer.write(sets[i]); 105 writer.write("(type "); 106 writer.write(Integer.toString(ps.type)); 107 writer.write(" size "); 108 writer.write(Integer.toString(ps.size)); 109 writer.write(" prev " ); 110 writer.write(Integer.toString(ps.previous)); 111 writer.write(" next " ); 112 writer.write(Integer.toString(ps.next)); 113 writer.write(" child " ); 114 writer.write(Integer.toString(ps.child)); 115 writer.write(" start block " ); 116 writer.write(Integer.toString(ps.startBlock)); 117 writer.write(")"); 118 writer.newLine(); 119 } 120 121 writer.flush(); 122 writer.close(); 123 } 124 125 128 void displayPropertySet(String ps, OutputStream os) 129 throws IOException ,BiffException 130 { 131 if (ps.equalsIgnoreCase("SummaryInformation")) 132 { 133 ps = BaseCompoundFile.SUMMARY_INFORMATION_NAME; 134 } 135 else if (ps.equalsIgnoreCase("DocumentSummaryInformation")) 136 { 137 ps = BaseCompoundFile.DOCUMENT_SUMMARY_INFORMATION_NAME; 138 } 139 else if (ps.equalsIgnoreCase("CompObj")) 140 { 141 ps = BaseCompoundFile.COMP_OBJ_NAME; 142 } 143 144 byte[] stream = compoundFile.getStream(ps); 145 os.write(stream); 146 } 147 148 } 149 | Popular Tags |