aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/hssf
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/poi/hssf')
-rw-r--r--src/java/org/apache/poi/hssf/dev/BiffViewer.java177
-rw-r--r--src/java/org/apache/poi/hssf/dev/EFBiffViewer.java6
-rw-r--r--src/java/org/apache/poi/hssf/dev/FormulaViewer.java14
-rw-r--r--src/java/org/apache/poi/hssf/dev/RecordLister.java7
-rw-r--r--src/java/org/apache/poi/hssf/record/HyperlinkRecord.java28
5 files changed, 176 insertions, 56 deletions
diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
index 3afd25a4ac..33fb1912bd 100644
--- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java
+++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
@@ -19,7 +19,6 @@ package org.apache.poi.hssf.dev;
import java.io.DataInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -31,8 +30,119 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.ArrayRecord;
+import org.apache.poi.hssf.record.AutoFilterInfoRecord;
+import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.BackupRecord;
+import org.apache.poi.hssf.record.BlankRecord;
+import org.apache.poi.hssf.record.BookBoolRecord;
+import org.apache.poi.hssf.record.BoolErrRecord;
+import org.apache.poi.hssf.record.BottomMarginRecord;
+import org.apache.poi.hssf.record.BoundSheetRecord;
+import org.apache.poi.hssf.record.CFHeader12Record;
+import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.CFRule12Record;
+import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.CalcCountRecord;
+import org.apache.poi.hssf.record.CalcModeRecord;
+import org.apache.poi.hssf.record.CodepageRecord;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.ContinueRecord;
+import org.apache.poi.hssf.record.CountryRecord;
+import org.apache.poi.hssf.record.DBCellRecord;
+import org.apache.poi.hssf.record.DConRefRecord;
+import org.apache.poi.hssf.record.DSFRecord;
+import org.apache.poi.hssf.record.DVALRecord;
+import org.apache.poi.hssf.record.DVRecord;
+import org.apache.poi.hssf.record.DateWindow1904Record;
+import org.apache.poi.hssf.record.DefaultColWidthRecord;
+import org.apache.poi.hssf.record.DefaultRowHeightRecord;
+import org.apache.poi.hssf.record.DeltaRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.DrawingGroupRecord;
+import org.apache.poi.hssf.record.DrawingRecordForBiffViewer;
+import org.apache.poi.hssf.record.DrawingSelectionRecord;
+import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.ExtSSTRecord;
+import org.apache.poi.hssf.record.ExtendedFormatRecord;
+import org.apache.poi.hssf.record.ExternSheetRecord;
+import org.apache.poi.hssf.record.ExternalNameRecord;
+import org.apache.poi.hssf.record.FeatHdrRecord;
+import org.apache.poi.hssf.record.FeatRecord;
+import org.apache.poi.hssf.record.FilePassRecord;
+import org.apache.poi.hssf.record.FileSharingRecord;
+import org.apache.poi.hssf.record.FnGroupCountRecord;
+import org.apache.poi.hssf.record.FontRecord;
+import org.apache.poi.hssf.record.FooterRecord;
+import org.apache.poi.hssf.record.FormatRecord;
+import org.apache.poi.hssf.record.FormulaRecord;
+import org.apache.poi.hssf.record.GridsetRecord;
+import org.apache.poi.hssf.record.GutsRecord;
+import org.apache.poi.hssf.record.HCenterRecord;
+import org.apache.poi.hssf.record.HeaderRecord;
+import org.apache.poi.hssf.record.HideObjRecord;
+import org.apache.poi.hssf.record.HorizontalPageBreakRecord;
+import org.apache.poi.hssf.record.HyperlinkRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.InterfaceEndRecord;
+import org.apache.poi.hssf.record.InterfaceHdrRecord;
+import org.apache.poi.hssf.record.IterationRecord;
+import org.apache.poi.hssf.record.LabelRecord;
+import org.apache.poi.hssf.record.LabelSSTRecord;
+import org.apache.poi.hssf.record.LeftMarginRecord;
+import org.apache.poi.hssf.record.MMSRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.record.MulBlankRecord;
+import org.apache.poi.hssf.record.MulRKRecord;
+import org.apache.poi.hssf.record.NameCommentRecord;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.NumberRecord;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.PaletteRecord;
+import org.apache.poi.hssf.record.PaneRecord;
+import org.apache.poi.hssf.record.PasswordRecord;
+import org.apache.poi.hssf.record.PasswordRev4Record;
+import org.apache.poi.hssf.record.PrecisionRecord;
+import org.apache.poi.hssf.record.PrintGridlinesRecord;
+import org.apache.poi.hssf.record.PrintHeadersRecord;
+import org.apache.poi.hssf.record.PrintSetupRecord;
+import org.apache.poi.hssf.record.ProtectRecord;
+import org.apache.poi.hssf.record.ProtectionRev4Record;
+import org.apache.poi.hssf.record.RKRecord;
+import org.apache.poi.hssf.record.RecalcIdRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException;
+import org.apache.poi.hssf.record.RefModeRecord;
+import org.apache.poi.hssf.record.RefreshAllRecord;
+import org.apache.poi.hssf.record.RightMarginRecord;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SCLRecord;
+import org.apache.poi.hssf.record.SSTRecord;
+import org.apache.poi.hssf.record.SaveRecalcRecord;
+import org.apache.poi.hssf.record.SelectionRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
+import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.hssf.record.StyleRecord;
+import org.apache.poi.hssf.record.SupBookRecord;
+import org.apache.poi.hssf.record.TabIdRecord;
+import org.apache.poi.hssf.record.TableRecord;
+import org.apache.poi.hssf.record.TableStylesRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
+import org.apache.poi.hssf.record.TopMarginRecord;
+import org.apache.poi.hssf.record.UncalcedRecord;
+import org.apache.poi.hssf.record.UnknownRecord;
+import org.apache.poi.hssf.record.UseSelFSRecord;
+import org.apache.poi.hssf.record.VCenterRecord;
+import org.apache.poi.hssf.record.VerticalPageBreakRecord;
+import org.apache.poi.hssf.record.WSBoolRecord;
+import org.apache.poi.hssf.record.WindowOneRecord;
+import org.apache.poi.hssf.record.WindowProtectRecord;
+import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.WriteAccessRecord;
+import org.apache.poi.hssf.record.WriteProtectRecord;
import org.apache.poi.hssf.record.chart.AreaFormatRecord;
import org.apache.poi.hssf.record.chart.AreaRecord;
import org.apache.poi.hssf.record.chart.AxisLineFormatRecord;
@@ -85,13 +195,16 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
/**
* Utillity for reading in BIFF8 records and displaying data from them.
* @see #main
*/
public final class BiffViewer {
- static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
+ static final String NEW_LINE_CHARS = System.getProperty("line.separator");
+ private static POILogger logger = POILogFactory.getLogger(BiffViewer.class);
private BiffViewer() {
// no instances of this class
@@ -114,8 +227,7 @@ public final class BiffViewer {
try {
hasNext = recStream.hasNextRecord();
} catch (LeftoverDataException e) {
- e.printStackTrace();
- System.err.println("Discarding " + recStream.remaining() + " bytes and continuing");
+ logger.log(POILogger.ERROR, "Discarding " + recStream.remaining() + " bytes and continuing", e);
recStream.readRemainder();
hasNext = recStream.hasNextRecord();
}
@@ -427,7 +539,7 @@ public final class BiffViewer {
* </table>
*
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws IOException {
// args = new String[] { "--out", "", };
CommandArgs cmdArgs;
try {
@@ -437,40 +549,37 @@ public final class BiffViewer {
return;
}
- try {
-
- PrintStream ps;
- if (cmdArgs.shouldOutputToFile()) {
- OutputStream os = new FileOutputStream(cmdArgs.getFile().getAbsolutePath() + ".out");
- ps = new PrintStream(os);
- } else {
- ps = System.out;
- }
-
- InputStream is = getPOIFSInputStream(cmdArgs.getFile());
+ PrintStream ps;
+ if (cmdArgs.shouldOutputToFile()) {
+ OutputStream os = new FileOutputStream(cmdArgs.getFile().getAbsolutePath() + ".out");
+ ps = new PrintStream(os);
+ } else {
+ ps = System.out;
+ }
- if (cmdArgs.shouldOutputRawHexOnly()) {
- int size = is.available();
- byte[] data = new byte[size];
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(cmdArgs.getFile(), true);
+ InputStream is = getPOIFSInputStream(fs);
+
+ if (cmdArgs.shouldOutputRawHexOnly()) {
+ int size = is.available();
+ byte[] data = new byte[size];
- is.read(data);
- HexDump.dump(data, 0, System.out, 0);
- } else {
- boolean dumpInterpretedRecords = cmdArgs.shouldDumpRecordInterpretations();
- boolean dumpHex = cmdArgs.shouldDumpBiffHex();
- boolean zeroAlignHexDump = dumpInterpretedRecords; // TODO - fix non-zeroAlign
- runBiffViewer(ps, is, dumpInterpretedRecords, dumpHex, zeroAlignHexDump,
- cmdArgs.suppressHeader());
- }
- ps.close();
- } catch (Exception e) {
- e.printStackTrace();
+ is.read(data);
+ HexDump.dump(data, 0, System.out, 0);
+ } else {
+ boolean dumpInterpretedRecords = cmdArgs.shouldDumpRecordInterpretations();
+ boolean dumpHex = cmdArgs.shouldDumpBiffHex();
+ boolean zeroAlignHexDump = dumpInterpretedRecords; // TODO - fix non-zeroAlign
+ runBiffViewer(ps, is, dumpInterpretedRecords, dumpHex, zeroAlignHexDump,
+ cmdArgs.suppressHeader());
}
+ is.close();
+ fs.close();
+ ps.close();
}
- protected static InputStream getPOIFSInputStream(File file)
+ protected static InputStream getPOIFSInputStream(NPOIFSFileSystem fs)
throws IOException, FileNotFoundException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(new FileInputStream(file));
String workbookName = HSSFWorkbook.getWorkbookDirEntryName(fs.getRoot());
return fs.createDocumentInputStream(workbookName);
}
diff --git a/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java b/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java
index 2893f31ed9..c87f5f73b9 100644
--- a/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java
+++ b/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java
@@ -25,6 +25,7 @@ import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
/**
*
@@ -42,7 +43,8 @@ public class EFBiffViewer
}
public void run() throws IOException {
- InputStream din = BiffViewer.getPOIFSInputStream(new File(file));
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
+ InputStream din = BiffViewer.getPOIFSInputStream(fs);
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(new HSSFListener()
@@ -55,6 +57,8 @@ public class EFBiffViewer
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
+ din.close();
+ fs.close();
}
public void setFile(String file)
diff --git a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java
index 69e0c3005b..eaa3fff0b5 100644
--- a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java
+++ b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java
@@ -18,6 +18,7 @@
package org.apache.poi.hssf.dev;
import java.io.File;
+import java.io.InputStream;
import java.util.List;
import org.apache.poi.hssf.model.HSSFFormulaParser;
@@ -25,6 +26,7 @@ import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.ss.formula.ptg.ExpPtg;
import org.apache.poi.ss.formula.ptg.FuncPtg;
import org.apache.poi.ss.formula.ptg.OperationPtg;
@@ -56,12 +58,10 @@ public class FormulaViewer
*
*/
- public void run()
- throws Exception
- {
- List<Record> records =
- RecordFactory
- .createRecords(BiffViewer.getPOIFSInputStream(new File(file)));
+ public void run() throws Exception {
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
+ InputStream is = BiffViewer.getPOIFSInputStream(fs);
+ List<Record> records = RecordFactory.createRecords(is);
for (int k = 0; k < records.size(); k++)
{
@@ -76,6 +76,8 @@ public class FormulaViewer
}
}
}
+ is.close();
+ fs.close();
}
private void listFormula(FormulaRecord record) {
diff --git a/src/java/org/apache/poi/hssf/dev/RecordLister.java b/src/java/org/apache/poi/hssf/dev/RecordLister.java
index 28896f2a11..7c626b8a12 100644
--- a/src/java/org/apache/poi/hssf/dev/RecordLister.java
+++ b/src/java/org/apache/poi/hssf/dev/RecordLister.java
@@ -25,6 +25,7 @@ import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
/**
* This is a low-level debugging class, which simply prints
@@ -49,7 +50,8 @@ public class RecordLister
public void run()
throws IOException
{
- InputStream din = BiffViewer.getPOIFSInputStream(new File(file));
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
+ InputStream din = BiffViewer.getPOIFSInputStream(fs);
RecordInputStream rinp = new RecordInputStream(din);
while(rinp.hasNextRecord()) {
@@ -77,6 +79,9 @@ public class RecordLister
System.out.println( formatData(data) );
}
}
+
+ din.close();
+ fs.close();
}
private static String formatSID(int sid) {
diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
index 618a86b062..07466f06e3 100644
--- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
+++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
@@ -124,16 +124,16 @@ public final class HyperlinkRecord extends StandardRecord {
StringBuilder sb = new StringBuilder(36);
int PREFIX_LEN = "0x".length();
- sb.append(HexDump.intToHex(_d1), PREFIX_LEN, 8);
+ sb.append(HexDump.intToHex(_d1).substring(PREFIX_LEN));
sb.append("-");
- sb.append(HexDump.shortToHex(_d2), PREFIX_LEN, 4);
+ sb.append(HexDump.shortToHex(_d2).substring(PREFIX_LEN));
sb.append("-");
- sb.append(HexDump.shortToHex(_d3), PREFIX_LEN, 4);
+ sb.append(HexDump.shortToHex(_d3).substring(PREFIX_LEN));
sb.append("-");
- char[] d4Chars = HexDump.longToHex(getD4());
- sb.append(d4Chars, PREFIX_LEN, 4);
+ String d4Chars = HexDump.longToHex(getD4());
+ sb.append(d4Chars.substring(PREFIX_LEN, PREFIX_LEN+4));
sb.append("-");
- sb.append(d4Chars, PREFIX_LEN + 4, 12);
+ sb.append(d4Chars.substring(PREFIX_LEN+4));
return sb.toString();
}
@@ -643,14 +643,14 @@ public final class HyperlinkRecord extends StandardRecord {
private static byte[] readTail(byte[] expectedTail, LittleEndianInput in) {
byte[] result = new byte[TAIL_SIZE];
in.readFully(result);
- if (false) { // Quite a few examples in the unit tests which don't have the exact expected tail
- for (int i = 0; i < expectedTail.length; i++) {
- if (expectedTail[i] != result[i]) {
- logger.log( POILogger.ERROR, "Mismatch in tail byte [" + i + "]"
- + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF));
- }
- }
- }
+// if (false) { // Quite a few examples in the unit tests which don't have the exact expected tail
+// for (int i = 0; i < expectedTail.length; i++) {
+// if (expectedTail[i] != result[i]) {
+// logger.log( POILogger.ERROR, "Mismatch in tail byte [" + i + "]"
+// + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF));
+// }
+// }
+// }
return result;
}
private static void writeTail(byte[] tail, LittleEndianOutput out) {