Beispiel #1
0
        public void parseEmbedded(InputStream inputStream, ContentHandler contentHandler, Metadata metadata, bool outputHtml)
        {
            Detector  detector    = new DefaultDetector();
            string    name        = metadata.get("resourceName");
            MediaType contentType = detector.detect(inputStream, metadata);

            if (contentType.getType() != "image")
            {
                return;
            }
            var  embeddedFile = name;
            File outputFile   = new File(@"C:\toHtml\images", embeddedFile);

            try
            {
                using (FileOutputStream os = new FileOutputStream(outputFile))
                {
                    var tin = inputStream as TikaInputStream;
                    if (tin != null)
                    {
                        if (tin.getOpenContainer() != null && tin.getOpenContainer() is DirectoryEntry)
                        {
                            POIFSFileSystem fs = new POIFSFileSystem();
                            fs.writeFilesystem(os);
                        }
                        else
                        {
                            IOUtils.copy(inputStream, os);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }