Closed Thread
Results 1 to 2 of 2

Thread: .NET VS Problem, "Unexpected EOF"

  1. #1
    hoser2001's Avatar
    hoser2001 is offline Programmer
    Join Date
    Jul 2006
    Posts
    175
    Rep Power
    0

    .NET VS Problem, "Unexpected EOF"

    Using Visual Studio 2005, C#, .NET 2.0

    Code:
    private void ZipAndSave(DataSet ds, DataSet ds2, string Destination) 
            { 
                ZipOutputStream s = new 
                ZipOutputStream(File.Create(Destination)); 
                s.SetLevel(9); 
                s.Password = ZPW; 
    
    
                ZipEntry schema = new ZipEntry("csMod.xsd"); 
                s.PutNextEntry(schema); 
                ds2.WriteXmlSchema(s); 
    
    
                ZipEntry data = new ZipEntry("csMod.xml"); 
                s.PutNextEntry(data); 
                ds.WriteXml(s); 
    
    
                s.Finish(); 
                s.Close(); 
            } 
    
    
    fsSend = new System.IO.FileStream(Destination, 
    System.IO.FileMode.Open, 
    System.IO.FileAccess.Read); 
                    byte[] b = new byte[fsSend.Length]; 
                    fsSend.Read(b, 0, (int)fsSend.Length); 
    
    
    ProcessCXML(b);//This is a function residing on server, a remote 
    function... 
    
    
    public void ProcessCXML(byte[] bytearray) 
                    { 
    
    
                            MemoryStream ms = new MemoryStream(); 
                            ms.Write(bytearray, 0, bytearray.Length); 
                                                    DataSet ds = 
    LoadDataFromFile(ms); 
                                    } 
    
    
    public DataSet LoadDataFromFile(MemoryStream ms) 
            { 
                Stream _trSchema = null; 
                DataSet ds = null; 
                Hashtable ht = new Hashtable(); 
    
    
                int BUFFER_SIZE = 2048; 
                ZipInputStream zin = null; 
                zin = new ZipInputStream(ms); 
                zin.Password = ZPW; 
    
    
                if (zin != null) 
                { 
                    ZipEntry entry = null; 
                    while ((entry = zin.GetNextEntry()) != null) 
                    { 
                        MemoryStream stream = new MemoryStream(); 
    
    
                        int size = BUFFER_SIZE; 
                        byte[] data = new byte[BUFFER_SIZE]; 
    
    
                        while (true) 
                        { 
                            size = zin.Read(data, 0, data.Length); 
                            if (size > 0) 
                            { 
                                stream.Write(data, 0, size); 
                            } 
                            else 
                            { 
                                break; 
                            } 
                        } 
    
    
                        stream.Position = 0; 
                        TextReader reader = new StreamReader(stream, 
    Encoding.UTF8); 
                        if (entry.Name.EndsWith(".xsd")) 
                        { 
                            ht.Add(entry.Name.ToLower(), stream); 
                        } 
                        else 
                        { 
                            ht.Add(entry.Name.ToLower(), reader); 
                        } 
                    } 
                } 
    
    
                if (ht["csmod.xml"] != null) 
                { 
                    ds = new DataSet(); 
                    try 
                    { 
                        ds.ReadXml((TextReader)ht["csmod.xml"]); 
                        if (ht["csmod.xsd"] != null) 
                        { 
                            _trSchema = (Stream)ht["csmod.xsd"]; 
                            _trSchema.Position = 0; 
                            ds.ReadXmlSchema(_trSchema); 
                        } 
                    } 
                    catch (Exception) 
                    { 
                        ds = null; 
                    } 
                } 
    
    
                return ds; 
            }
    This is the details of the error I get from the server:


    Error in ProcessCXML: Unexpected EOF at
    ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputBuffer.Fill()
    at
    ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputBuffer.ReadLeB**
    yte()
    at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNext Entry()
    at CSRemoteServerService.ServerImpl.LoadDataFromFile( MemoryStream
    ms)
    at CSRemoteServerService.ServerImpl.ProcessCXML(Byte[] bytearray)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    hoser2001's Avatar
    hoser2001 is offline Programmer
    Join Date
    Jul 2006
    Posts
    175
    Rep Power
    0
    Figured out my mistake....

    Right before I load the ZipStream with the Memory Stream, I have to reset the position of the memory stream...

    ms.Position = 0;


    Then I can load it into the ZipInput Stream....

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MASM How To Use "Open" And "Save As" (Win32 API) ?
    By RhetoricalRuvim in forum Assembly
    Replies: 12
    Last Post: 08-13-2011, 04:10 PM
  2. "\r\n" are for some reason turned into "\r\n\r\n"; what's wrong?
    By RhetoricalRuvim in forum Ruby Programming
    Replies: 1
    Last Post: 08-06-2011, 05:55 PM
  3. Alex G. CSS "Sexy Buttons" - what about "submit on 'ENTER'" ?
    By shackrock in forum JavaScript and CSS
    Replies: 7
    Last Post: 12-05-2010, 04:57 PM
  4. Replies: 2
    Last Post: 11-01-2010, 11:52 PM
  5. "Easy" Math.random() problem
    By Darkone85 in forum Java Help
    Replies: 5
    Last Post: 03-04-2010, 08:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts