?
Solved

header checksum illegal in csharpzip library conversion

Posted on 2011-10-11
9
Medium Priority
?
1,453 Views
Last Modified: 2012-08-14

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!
0
Comment
Question by:codefinger
  • 5
  • 4
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36947548
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
 

Author Comment

by:codefinger
ID: 36948638
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36949693
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:codefinger
ID: 36950321

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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36951552
Show us the full code in which you are reading files.
0
 

Author Comment

by:codefinger
ID: 36953190
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36954383
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
 

Accepted Solution

by:
codefinger earned 0 total points
ID: 37010656
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
 

Author Closing Comment

by:codefinger
ID: 37035324
Found my own way around the problem.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question