PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/ppt/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java

https://github.com/minstrelsy/POI-Android
Java | 123 lines | 89 code | 14 blank | 20 comment | 12 complexity | f08b2eea782e030096ccaf8367f64ad3 MD5 | raw file
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hdgf.dev;
  16. import java.io.FileInputStream;
  17. import org.apache.poi.hdgf.HDGFDiagram;
  18. import org.apache.poi.hdgf.chunks.Chunk;
  19. import org.apache.poi.hdgf.chunks.Chunk.Command;
  20. import org.apache.poi.hdgf.pointers.Pointer;
  21. import org.apache.poi.hdgf.streams.ChunkStream;
  22. import org.apache.poi.hdgf.streams.PointerContainingStream;
  23. import org.apache.poi.hdgf.streams.Stream;
  24. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  25. /**
  26. * Developer helper class to dump out the pointer+stream structure
  27. * of a Visio file
  28. */
  29. public final class VSDDumper {
  30. public static void main(String[] args) throws Exception {
  31. if(args.length == 0) {
  32. System.err.println("Use:");
  33. System.err.println(" VSDDumper <filename>");
  34. System.exit(1);
  35. }
  36. HDGFDiagram hdgf = new HDGFDiagram(
  37. new POIFSFileSystem(new FileInputStream(args[0]))
  38. );
  39. System.out.println("Opened " + args[0]);
  40. System.out.println("The document claims a size of " +
  41. hdgf.getDocumentSize() + " (" +
  42. Long.toHexString(hdgf.getDocumentSize()) + ")");
  43. System.out.println();
  44. dumpStream(hdgf.getTrailerStream(), 0);
  45. }
  46. public static void dumpStream(Stream stream, int indent) {
  47. String ind = "";
  48. for(int i=0; i<indent; i++) {
  49. ind += " ";
  50. }
  51. String ind2 = ind + " ";
  52. String ind3 = ind2 + " ";
  53. Pointer ptr = stream.getPointer();
  54. System.out.println(ind + "Stream at\t" + ptr.getOffset() +
  55. " - " + Integer.toHexString(ptr.getOffset()));
  56. System.out.println(ind + " Type is\t" + ptr.getType() +
  57. " - " + Integer.toHexString(ptr.getType()));
  58. System.out.println(ind + " Format is\t" + ptr.getFormat() +
  59. " - " + Integer.toHexString(ptr.getFormat()));
  60. System.out.println(ind + " Length is\t" + ptr.getLength() +
  61. " - " + Integer.toHexString(ptr.getLength()));
  62. if(ptr.destinationCompressed()) {
  63. int decompLen = stream._getContentsLength();
  64. System.out.println(ind + " DC.Length is\t" + decompLen +
  65. " - " + Integer.toHexString(decompLen));
  66. }
  67. System.out.println(ind + " Compressed is\t" + ptr.destinationCompressed());
  68. System.out.println(ind + " Stream is\t" + stream.getClass().getName());
  69. byte[] db = stream._getStore()._getContents();
  70. String ds = "";
  71. if(db.length >= 8) {
  72. for(int i=0; i<8; i++) {
  73. if(i>0) ds += ", ";
  74. ds += db[i];
  75. }
  76. }
  77. System.out.println(ind + " First few bytes are\t" + ds);
  78. if(stream instanceof PointerContainingStream) {
  79. PointerContainingStream pcs = (PointerContainingStream)stream;
  80. System.out.println(ind + " Has " +
  81. pcs.getPointedToStreams().length + " children:");
  82. for(int i=0; i<pcs.getPointedToStreams().length; i++) {
  83. dumpStream(pcs.getPointedToStreams()[i], (indent+1));
  84. }
  85. }
  86. if(stream instanceof ChunkStream) {
  87. ChunkStream cs = (ChunkStream)stream;
  88. System.out.println(ind + " Has " + cs.getChunks().length +
  89. " chunks:");
  90. for(int i=0; i<cs.getChunks().length; i++) {
  91. Chunk chunk = cs.getChunks()[i];
  92. System.out.println(ind2 + "" + chunk.getName());
  93. System.out.println(ind2 + " Length is " + chunk._getContents().length + " (" + Integer.toHexString(chunk._getContents().length) + ")");
  94. System.out.println(ind2 + " OD Size is " + chunk.getOnDiskSize() + " (" + Integer.toHexString(chunk.getOnDiskSize()) + ")");
  95. System.out.println(ind2 + " T / S is " + chunk.getTrailer() + " / " + chunk.getSeparator());
  96. System.out.println(ind2 + " Holds " + chunk.getCommands().length + " commands");
  97. for(int j=0; j<chunk.getCommands().length; j++) {
  98. Command command = chunk.getCommands()[j];
  99. System.out.println(ind3 + "" +
  100. command.getDefinition().getName() +
  101. " " + command.getValue()
  102. );
  103. }
  104. }
  105. }
  106. }
  107. }