header checksum illegal in csharpzip library conversion


The following code works on most, but not all, of the files I have been tasked to convert to another format:
 
oInflater =

New ICSharpCode.SharpZipLib.Zip.Compression.Inflater(False)

oInflater.SetInput(oCCMSReturn.ByteArrayFileObject, 0, oCCMSReturn.ByteArrayFileObject.Length)

sb =

New StringBuilder()

 

 
Do While Not oInflater.IsFinished

     iBytesInflated = oInflater.Inflate(myBuffer)

     sb.Append(Encoding.UTF8.GetString(myBuffer, 0, iBytesInflated))

 

 

Loop

xd.LoadXml(sb.ToString.Substring(1, sb.Length - 1))

Open in new window


When it fails, there is an error message "Header checksum illegal" as soon as the loop begins.
I know absolutely nothing about this code except what I have written here.  It was created by
two people, neither one of which are still available.

Are there any entries I can make in the vb.net code that might get past the problem with the files
that are failing?   (I can predict which files are going to fail by their extensions...OID files will pass, OIN files will not, and yes, I am sure no one out there has ever heard of either one of these extensions. They are INK files, similar (but not similar enough - the Windows Journal Viewer cannot load them) to Windows Journal Files, originally created on a Tablet PC.

I posted the same question in the SharpDevelop community and was left with deafening silence

Thanks in advance for your help!
codefingerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
Change this

Do While Not oInflater.IsFinished

     iBytesInflated = oInflater.Inflate(myBuffer)

     sb.Append(Encoding.UTF8.GetString(myBuffer, 0, iBytesInflated))

 

 

Loop


to



Do While Not oInflater.IsFinished
Try
     iBytesInflated = oInflater.Inflate(myBuffer)

     sb.Append(Encoding.UTF8.GetString(myBuffer, 0, iBytesInflated))

Catch
End Try
Loop
0
codefingerAuthor Commented:
CodeCruiser,
   
   Won't that cause an endless loop?  The error continues to occur, so the inflater will never
reach a "finished" state.

   Trying it now, that is what I am seeing so far

0
CodeCruiserCommented:
Oh yes. Just noticed the loop. You want the processing to continue for other files right? Where is that loop? Put try catch in that loop.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

codefingerAuthor Commented:

Not worried about other files.  I want to be able to convert the OIN files.  

Hoping there is a way past the error so the inflation (and hopefully, subsequent conversion) can continue despite "header checksum illegal" message.
0
CodeCruiserCommented:
Show us the full code in which you are reading files.
0
codefingerAuthor Commented:
Okay, but I think it may confuse the issue...TMI...but here goes...
<WebMethod()> _
    Public Function ConvertInkFileToTiff(ByVal str_uniqueid As String) As ConversionResponse

        Dim oCCMS As CCMS.CCMSService = Nothing
        Dim oCCMSReturn As CCMS.CCMSMessage
        'Dim cFileInfo As BOL_Common.FileInfo
        Dim oInflater As ICSharpCode.SharpZipLib.Zip.Compression.Inflater
        Dim iBytesInflated As Integer
        Dim myBuffer(2047) As Byte
        '    Dim streamXML As IO.StringReader
        Dim sb As New StringBuilder()
        Dim xd As New System.Xml.XmlDocument()
        Dim node As System.Xml.XmlNode
        Dim nodePage As System.Xml.XmlNode
        Dim baBackgroundGIF() As Byte = Nothing
        Dim streamXML As IO.StringReader
        Dim oInk As New Microsoft.Ink.Ink()
        Dim objBitmapGif, objBitmapJpeg As Drawing.Bitmap
        Dim objImage As Image
        Dim strfilename As String
        Dim str_errmsg As String = Nothing

        Dim str_ccms_url As String = Nothing


        Dim strmBackground As New IO.MemoryStream()

        Dim strmTemp As New IO.MemoryStream()
        Dim rend As New Microsoft.Ink.Renderer()

        Dim cv As New ConversionResponse
        Try


            cv.Success = True

            oCCMS = New CCMS.CCMSService()
            str_ccms_url = ConfigurationManager.AppSettings("CCMSLocation")
            oCCMS.Url = str_ccms_url


            Dim iPage As Integer = 1


            'Get Ink on form data from CCMS
            oCCMSReturn = oCCMS.GetObjectByUniqueID(str_uniqueid, " ")

            'Was this call a success? 

            If oCCMSReturn.FunctionSuccess = True Then
                strfilename = oCCMSReturn.FileName
                'Make sure this is a valid INK file.
                LogProgress("Converting " & strfilename, "LOG")
                'We need to clear session variables later
                'cBOL_Common.CleanupInkOnFormLater()


                If Right(strfilename, 3) = "OID" Then 'Uncompress the returned object
                    oInflater = New ICSharpCode.SharpZipLib.Zip.Compression.Inflater(False)
                    oInflater.SetInput(oCCMSReturn.ByteArrayFileObject, 0, oCCMSReturn.ByteArrayFileObject.Length)
                    sb = New StringBuilder()
                    LogProgress("Inflating " & strfilename, "log")
                    Do While Not oInflater.IsFinished
                        iBytesInflated = oInflater.Inflate(myBuffer)
                        sb.Append(Encoding.UTF8.GetString(myBuffer, 0, iBytesInflated))
                    Loop
                    LogProgress("Inflated " & strfilename, "log")
                    xd.LoadXml(sb.ToString.Substring(1, sb.Length - 1))
                ElseIf Right(strfilename, 3) = "OIN" Then

                    'LogProgress(strfilename & " cannot be converted. ", "oin")
                    'cv.Message = "Cannot convert ink files with extension OIN"
                    'cv.Success = False
                    'Return cv

                    oInflater = New ICSharpCode.SharpZipLib.Zip.Compression.Inflater(False)
                    oInflater.SetInput(oCCMSReturn.ByteArrayFileObject, 0, oCCMSReturn.ByteArrayFileObject.Length)
                    sb = New StringBuilder()
                    LogProgress("Inflating " & strfilename, "log")
                    
                    Do While Not oInflater.IsFinished
                        iBytesInflated = oInflater.Inflate(myBuffer)
                        sb.Append(Encoding.UTF8.GetString(myBuffer, 0, iBytesInflated))
                    Loop

                    LogProgress("Inflated " & strfilename, "log")
                    xd.LoadXml(sb.ToString.Substring(1, sb.Length - 1))

                End If




                'Look at the XML (throw away first byte)
                streamXML = New IO.StringReader(sb.ToString.Substring(1, sb.Length - 1))
                xd = New System.Xml.XmlDocument()
                xd.Load(streamXML)
                '   xd.LoadXml(sb.ToString.Substring(1, sb.Length - 1))

                'Determine how many pages are in the INK file.:
                '  -------------------------------------------------
                Dim pgcnt As Integer = 0
                iPage = 1
                nodePage = xd.SelectSingleNode("//P" & iPage)
                iPage = 0
                Do While Not nodePage Is Nothing
                    pgcnt = pgcnt + 1
                    iPage = iPage + 1
                    nodePage = xd.SelectSingleNode("//P" & iPage)
                Loop
                '----------------------------------------------------
                LogProgress("Converting " & (pgcnt - 1).ToString & " pages.", "log")
                For iPage = 1 To pgcnt - 1
                    strmTemp = New IO.MemoryStream()
                    strmBackground = New IO.MemoryStream
                    baBackgroundGIF = Nothing
                    objBitmapGif = Nothing
                    objBitmapJpeg = Nothing
                    nodePage = Nothing
                    node = Nothing
                    objImage = Nothing
                    oInk = New Microsoft.Ink.Ink()
                    nodePage = xd.SelectSingleNode("//P" & iPage)
                    If Not nodePage Is Nothing Then
                        'Get the first page background image
                        node = nodePage.SelectSingleNode(".//Static")
                        If Not node Is Nothing Then
                            baBackgroundGIF = Convert.FromBase64String(node.InnerXml)
                            strmBackground = New IO.MemoryStream(baBackgroundGIF)
                        End If
                        'Get the first page ink
                        node = nodePage.SelectSingleNode(".//Ink")
                        If Not node Is Nothing Then

                            oInk.Load(Encoding.UTF8.GetBytes(node.InnerXml))
                            DeleteLongerStrokes(12001, oInk)
                            objBitmapGif = System.Drawing.Bitmap.FromStream(strmBackground)
                            'Scale to these dimensions to line up with INK
                            objBitmapJpeg = ResizeAndConvertToJpeg(objBitmapGif, 971, 756)

                            objBitmapJpeg.Save(strmTemp, System.Drawing.Imaging.ImageFormat.Jpeg)
                            'objBitmapJpeg.Save(strmTemp, System.Drawing.Imaging.ImageFormat.Tiff)

                            objImage = Bitmap.FromStream(strmTemp)


                            Dim graphicsImage As Graphics = Nothing
                            Dim dib As DibGraphicsBuffer.DibGraphicsBuffer = Nothing
                            Dim graphicsPanel As Graphics = Nothing
                            Dim graphicsTemp As Graphics = Nothing
                            Dim PanelInk As New Windows.Forms.Panel()
                            Dim theInkOverlay As New Microsoft.Ink.InkOverlay()
                            Dim iBluePlateX As Integer

                            graphicsImage = Graphics.FromImage(objBitmapJpeg)
                            dib = New DibGraphicsBuffer.DibGraphicsBuffer()
                            ' Create temporary screen graphics
                            PanelInk.Width = objBitmapJpeg.Width
                            PanelInk.Height = objBitmapJpeg.Height
                            graphicsPanel = PanelInk.CreateGraphics()
                            ' Create temporary graphics from the Device Independent Bitmap
                            graphicsTemp = dib.RequestBuffer(graphicsPanel, PanelInk.Width, PanelInk.Height)
                            graphicsTemp.Clear(PanelInk.BackColor)
                            graphicsTemp.DrawImageUnscaled(objImage, New Point(0, 0))

                            'Draw the strokes onto the temporary image
                            theInkOverlay.Ink = oInk
                            theInkOverlay.Renderer.Draw(graphicsTemp, theInkOverlay.Ink.Strokes)
                            'Use the buffer to paint onto the final image
                            dib.PaintBuffer(graphicsImage, 0, 0)


                            'Write to browser
                            'HttpContext.Current.Response.Buffer = True
                            'HttpContext.Current.Response.ContentType = "image/jpeg"
                            'objBitmapJpeg.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg)

                            If Not Me.SaveToTIFF(strfilename, objBitmapJpeg, iPage, str_errmsg) Then
                                LogProgress("Could not convert " & strfilename & " An error occurred. See error log for this time.", "log")
                                LogProgress("Error processing " & strfilename & ". Page " & iPage.ToString & ":" & str_errmsg, "err")
                                cv.Success = False
                                cv.Message = "Error processing " & strfilename & ". Page " & iPage.ToString & ":" & str_errmsg
                            Else
                                LogProgress("Page " & iPage.ToString & " was Converted", "LOG")
                            End If
                        End If

                    End If
                Next

                If cv.Success Then
                    LogProgress(strfilename & " was converted.", "log")
                End If


            Else
                cv.Success = False
                cv.Message = "Call to CCMS did not succeed." & " " & oCCMSReturn.ErrDescription
                LogProgress("An error occurred. See error log for this time. ", "log")
                LogProgress("Call to CCMS for " & strfilename & " did not succeed. " & ":" & oCCMSReturn.ErrDescription, "err")
            End If
        Catch ex As Exception

            cv.Success = False
            cv.Message = ex.Message
            If Not ex.InnerException Is Nothing Then
                cv.Message = cv.Message & " " & ex.InnerException.Message
            End If
            LogProgress("Could not convert " & strfilename & " An error occurred. See error log for this time.", "log")
            LogProgress("Could not convert " & strfilename & ":" & cv.Message, "ERR")
        Finally
            'Dim oCCMS As CCMS.CCMSService = Nothing

            If Not oCCMS Is Nothing Then
                oCCMS.Dispose()
            End If

            'Dim oCCMSReturn As CCMS.CCMSMessage
            If Not oCCMSReturn Is Nothing Then
                oCCMSReturn = Nothing
            End If
            ''Dim cFileInfo As BOL_Common.FileInfo

            'Dim oInflater As ICSharpCode.SharpZipLib.Zip.Compression.Inflater
            If Not oInflater Is Nothing Then
                oInflater = Nothing
            End If
            'Dim iBytesInflated As Integer
            'Dim myBuffer(2047) As Byte

            If Not myBuffer Is Nothing Then
                myBuffer = Nothing
            End If

            ''    Dim streamXML As IO.StringReader
            If Not streamXML Is Nothing Then
                streamXML.Dispose()
            End If

            'Dim sb As New StringBuilder()

            If Not sb Is Nothing Then
                sb = Nothing
            End If

            'Dim xd As New System.Xml.XmlDocument()
            If Not xd Is Nothing Then
                xd = Nothing
            End If

            'Dim node As System.Xml.XmlNode
            If Not node Is Nothing Then
                node = Nothing
            End If

            'Dim nodePage As System.Xml.XmlNode
            If Not nodePage Is Nothing Then
                nodePage = Nothing
            End If
            'Dim baBackgroundGIF() As Byte = Nothing

            If Not baBackgroundGIF Is Nothing Then
                baBackgroundGIF = Nothing
            End If


            'Dim oInk As New Microsoft.Ink.Ink()

            If Not oInk Is Nothing Then
                oInk.Dispose()
            End If

            'Dim objBitmapGif, objBitmapJpeg As Drawing.Bitmap
            If Not objBitmapGif Is Nothing Then
                objBitmapGif.Dispose()
            End If


            'Dim objImage As Image
            If Not objImage Is Nothing Then
                objImage.Dispose()
            End If

            'Dim strmBackground As New IO.MemoryStream()
            If Not strmBackground Is Nothing Then
                strmBackground.Dispose()
            End If

            'Dim strmTemp As New IO.MemoryStream()
            If Not strmTemp Is Nothing Then
                strmTemp.Dispose()
            End If

            'Dim rend As New Microsoft.Ink.Renderer()
            If Not rend Is Nothing Then
                rend = Nothing
            End If

        End Try

        Return cv

    End Function

Open in new window

0
CodeCruiserCommented:
This function is converting one file. You have it in a loop somewhere to call it against each file. Now lets clarify one thing with regards to your question

My understanding is that you have a bunch of files to convert. If this function errors out on one file, you want it to continue converting other files (other files of same type). Is this right? But you confused me with your comment http:#36950321 and I dont think the conversion can continue if you get the header error.
0
codefingerAuthor Commented:
True, getting the header error stops conversion, I was just hoping for some way to avoid the header error, but I don't think there is a way.

I found other code where the files are being viewed by their native application.  Then the code does a copy and paste from the native viewer into a picture box on a data dynamics active report.  I was able to adopt that code to build a converter that converts the OIN files to PDF's.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codefingerAuthor Commented:
Found my own way around the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.