Пример #1
0
        private static void ReadModule(DocumentInputStream dis, String name, ModuleMap modules)
        {
            Module module = modules.Get(name);

            // TODO Refactor this to fetch dir then do the rest
            if (module == null)
            {
                // no DIR stream with offsets yet, so store the compressed bytes for later
                module = new Module();
                modules.Put(name, module);
                module.Read(dis);
            }
            else
            {
                if (module.offset == null)
                {
                    //This should not happen. bug 59858
                    throw new IOException("Module offset for '" + name + "' was never Read.");
                }
                // we know the offset already, so decompress immediately on-the-fly
                long skippedBytes = dis.Skip(module.offset.Value);
                if (skippedBytes != module.offset)
                {
                    throw new IOException("tried to skip " + module.offset + " bytes, but actually skipped " + skippedBytes + " bytes");
                }
                InputStream stream = new RLEDecompressingInputStream(dis);
                module.Read(stream);
                stream.Close();
            }
        }
Пример #2
0
        /**
         * Reads module from DIR node in input stream and Adds it to the modules map for decompression later
         * on the second pass through this function, the module will be decompressed
         *
         * Side-effects: Adds a new module to the module map or Sets the buf field on the module
         * to the decompressed stream contents (the VBA code for one module)
         *
         * @param in the Run-length encoded input stream to read from
         * @param streamName the stream name of the module
         * @param modules a map to store the modules
         * @throws IOException
         */
        private static void ReadModule(RLEDecompressingInputStream in1, String streamName, ModuleMap modules)
        {
            int    moduleOffset = in1.ReadInt();
            Module module       = modules.Get(streamName);

            if (module == null)
            {
                // First time we've seen the module. Add it to the ModuleMap and decompress it later
                module        = new Module();
                module.offset = moduleOffset;
                modules.Put(streamName, module);
                // Would Adding module.Read(in1) here be correct?
            }
            else
            {
                // Decompress a previously found module and store the decompressed result into module.buf
                InputStream stream = new RLEDecompressingInputStream(
                    new MemoryStream(module.buf, moduleOffset, module.buf.Length - moduleOffset)
                    );
                module.Read(stream);
                stream.Close();
            }
        }