📄 escherdump.java
字号:
/* ==================================================================== Copyright 2002-2004 Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.==================================================================== */ package org.apache.poi.ddf;import org.apache.poi.util.HexDump;import org.apache.poi.util.HexRead;import org.apache.poi.util.LittleEndian;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintStream;import java.util.zip.InflaterInputStream;/** * Used to dump the contents of escher records to a PrintStream. * * @author Glen Stampoultzis (glens at apache.org) */public class EscherDump{ public EscherDump() { } /** * Decodes the escher stream from a byte array and dumps the results to * a print stream. * * @param data The data array containing the escher records. * @param offset The starting offset within the data array. * @param size The number of bytes to read. * @param out The output stream to write the results to. * */ public void dump( byte[] data, int offset, int size, PrintStream out ) throws IOException, LittleEndian.BufferUnderrunException { EscherRecordFactory recordFactory = new DefaultEscherRecordFactory(); int pos = offset; while ( pos < offset + size ) { EscherRecord r = recordFactory.createRecord(data, pos); int bytesRead = r.fillFields(data, pos, recordFactory ); System.out.println( r.toString() ); pos += bytesRead; } } /** * This version of dump is a translation from the open office escher dump routine. * * @param maxLength The number of bytes to read * @param in An input stream to read from. * @param out An output stream to write to. */ public void dumpOld( long maxLength, InputStream in, PrintStream out ) throws IOException, LittleEndian.BufferUnderrunException { long remainingBytes = maxLength; short options; // 4 bits for the version and 12 bits for the instance short recordId; int recordBytesRemaining; // including enclosing records StringBuffer stringBuf = new StringBuffer(); short nDumpSize; String recordName; boolean atEOF = false; while ( !atEOF && ( remainingBytes > 0 ) ) { stringBuf = new StringBuffer(); options = LittleEndian.readShort( in ); recordId = LittleEndian.readShort( in ); recordBytesRemaining = LittleEndian.readInt( in ); remainingBytes -= 2 + 2 + 4; switch ( recordId ) { case (short) 0xF000: recordName = "MsofbtDggContainer"; break; case (short) 0xF006: recordName = "MsofbtDgg"; break; case (short) 0xF016: recordName = "MsofbtCLSID"; break; case (short) 0xF00B: recordName = "MsofbtOPT"; break; case (short) 0xF11A: recordName = "MsofbtColorMRU"; break; case (short) 0xF11E: recordName = "MsofbtSplitMenuColors"; break; case (short) 0xF001: recordName = "MsofbtBstoreContainer"; break; case (short) 0xF007: recordName = "MsofbtBSE"; break; case (short) 0xF002: recordName = "MsofbtDgContainer"; break; case (short) 0xF008: recordName = "MsofbtDg"; break; case (short) 0xF118: recordName = "MsofbtRegroupItem"; break; case (short) 0xF120: recordName = "MsofbtColorScheme"; break; case (short) 0xF003: recordName = "MsofbtSpgrContainer"; break; case (short) 0xF004: recordName = "MsofbtSpContainer"; break; case (short) 0xF009: recordName = "MsofbtSpgr"; break; case (short) 0xF00A: recordName = "MsofbtSp"; break; case (short) 0xF00C: recordName = "MsofbtTextbox"; break; case (short) 0xF00D: recordName = "MsofbtClientTextbox"; break; case (short) 0xF00E: recordName = "MsofbtAnchor"; break; case (short) 0xF00F: recordName = "MsofbtChildAnchor"; break; case (short) 0xF010: recordName = "MsofbtClientAnchor"; break; case (short) 0xF011: recordName = "MsofbtClientData"; break; case (short) 0xF11F: recordName = "MsofbtOleObject"; break; case (short) 0xF11D: recordName = "MsofbtDeletedPspl"; break; case (short) 0xF005: recordName = "MsofbtSolverContainer"; break; case (short) 0xF012: recordName = "MsofbtConnectorRule"; break; case (short) 0xF013: recordName = "MsofbtAlignRule"; break; case (short) 0xF014: recordName = "MsofbtArcRule"; break; case (short) 0xF015: recordName = "MsofbtClientRule"; break; case (short) 0xF017: recordName = "MsofbtCalloutRule"; break; case (short) 0xF119: recordName = "MsofbtSelection"; break; case (short) 0xF122: recordName = "MsofbtUDefProp"; break; default: if ( recordId >= (short) 0xF018 && recordId <= (short) 0xF117 ) recordName = "MsofbtBLIP"; else if ( ( options & (short) 0x000F ) == (short) 0x000F ) recordName = "UNKNOWN container"; else recordName = "UNKNOWN ID"; } stringBuf.append( " " ); stringBuf.append( HexDump.toHex( recordId ) ); stringBuf.append( " " ).append( recordName ).append( " [" ); stringBuf.append( HexDump.toHex( options ) ); stringBuf.append( ',' ); stringBuf.append( HexDump.toHex( recordBytesRemaining ) ); stringBuf.append( "] instance: " ); stringBuf.append( HexDump.toHex( ( (short) ( options >> 4 ) ) ) ); out.println( stringBuf.toString() ); if ( recordId == (short) 0xF007 && 36 <= remainingBytes && 36 <= recordBytesRemaining ) { // BSE, FBSE // ULONG nP = pIn->GetRecPos(); byte n8; // short n16; // int n32; stringBuf = new StringBuffer( " btWin32: " ); n8 = (byte) in.read(); stringBuf.append( HexDump.toHex( n8 ) ); stringBuf.append( getBlipType( n8 ) ); stringBuf.append( " btMacOS: " ); n8 = (byte) in.read(); stringBuf.append( HexDump.toHex( n8 ) ); stringBuf.append( getBlipType( n8 ) ); out.println( stringBuf.toString() ); out.println( " rgbUid:" ); HexDump.dump( in, out, 0, 16 ); out.print( " tag: " ); outHex( 2, in, out ); out.println(); out.print( " size: " ); outHex( 4, in, out ); out.println(); out.print( " cRef: " ); outHex( 4, in, out ); out.println(); out.print( " offs: " ); outHex( 4, in, out ); out.println(); out.print( " usage: " ); outHex( 1, in, out ); out.println(); out.print( " cbName: " ); outHex( 1, in, out ); out.println(); out.print( " unused2: " ); outHex( 1, in, out ); out.println(); out.print( " unused3: " ); outHex( 1, in, out ); out.println(); // subtract the number of bytes we've read remainingBytes -= 36; //n -= pIn->GetRecPos() - nP; recordBytesRemaining = 0; // loop to MsofbtBLIP } else if ( recordId == (short) 0xF010 && 0x12 <= remainingBytes && 0x12 <= recordBytesRemaining ) { // ClientAnchor //ULONG nP = pIn->GetRecPos(); // short n16; out.print( " Flag: " ); outHex( 2, in, out ); out.println(); out.print( " Col1: " ); outHex( 2, in, out ); out.print( " dX1: " ); outHex( 2, in, out ); out.print( " Row1: " ); outHex( 2, in, out ); out.print( " dY1: " ); outHex( 2, in, out ); out.println(); out.print( " Col2: " ); outHex( 2, in, out ); out.print( " dX2: " ); outHex( 2, in, out ); out.print( " Row2: " ); outHex( 2, in, out ); out.print( " dY2: " ); outHex( 2, in, out ); out.println(); remainingBytes -= 18; recordBytesRemaining -= 18; } else if ( recordId == (short) 0xF00B || recordId == (short) 0xF122 ) { // OPT int nComplex = 0; out.println( " PROPID VALUE" ); while ( recordBytesRemaining >= 6 + nComplex && remainingBytes >= 6 + nComplex ) { short n16; int n32; n16 = LittleEndian.readShort( in ); n32 = LittleEndian.readInt( in ); recordBytesRemaining -= 6; remainingBytes -= 6; out.print( " " ); out.print( HexDump.toHex( n16 ) ); out.print( " (" ); int propertyId = n16 & (short) 0x3FFF; out.print( " " + propertyId ); if ( ( n16 & (short) 0x8000 ) == 0 ) { if ( ( n16 & (short) 0x4000 ) != 0 ) out.print( ", fBlipID" ); out.print( ") " ); out.print( HexDump.toHex( n32 ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -