Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:39:21+00:00 2026-05-14T15:39:21+00:00

Have some data in a sybase image type column that I want to use

  • 0

Have some data in a sybase image type column that I want to use in a C# app. The data has been compressed by Java using the java.util.zip package. I wanted to test that I could decompress the data in C#. So I wrote a test app that pulls it out of the database:

byte[] bytes = (byte[])reader.GetValue(0);  

This gives me a compressed byte[] of 2479 length.
Then I pass this to a seemingly standard C# decompression method:

public static byte[] Decompress(byte[] gzBuffer)
{
    MemoryStream ms = new MemoryStream();
    int msgLength = BitConverter.ToInt32(gzBuffer, 0);
    ms.Write(gzBuffer, 4, gzBuffer.Length - 4);
    byte[] buffer = new byte[msgLength];

    ms.Position = 0;
    GZipStream zip = new GZipStream(ms, CompressionMode.Decompress);
    zip.Read(buffer, 0, buffer.Length);

    return buffer;
}  

The value for msgLength is 1503501432 which seems way out of range. The original document should be in the range of 5K -50k. Anyway when I use that value to create “buffer” not surprisingly I get an OutOfMemoryException.
What is happening?
Jim

The Java compress method is as follows:

public byte[] compress(byte[] bytes) throws Exception {
    byte[] results = new byte[bytes.length];
    Deflater deflator = new Deflater();
    deflater.setInput(bytes);
    deflater.finish();
    int len = deflater.deflate(results);
    byte[] out = new byte[len];
    for(int i=0; i<len; i++) {
        out[i] = results[i];
    }
    return(out);
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:39:22+00:00Added an answer on May 14, 2026 at 3:39 pm

    As I cant see your java code, I can only guess you are compressing your data to a zip file stream. Therefore it will obviously fail if you are trying to decompress that stream with a gzip decompression in c#. Either you change your java code to a gzip compression (Example here at the bottom of the page), or you decompress the zip file stream in c# with an appropriate library (e.g. SharpZipLib).

    Update

    Ok now, I see you are using deflate for the compression in java. So, obviously you have to use the same algorithm in c#: System.IO.Compression.DeflateStream

    public static byte[] Decompress(byte[] buffer)
    {
        using (MemoryStream ms = new MemoryStream(buffer))
        using (Stream zipStream = new DeflateStream(ms, 
                              CompressionMode.Decompress, true))
        {
            int initialBufferLength = buffer.Length * 2;
    
            byte[] buffer = new byte[initialBufferLength];
            bool finishedExactly = false;
            int read = 0;
            int chunk;
    
            while (!finishedExactly && 
                  (chunk = zipStream.Read(buffer, read, buffer.Length - read)) > 0)
            {
                read += chunk;
    
                if (read == buffer.Length)
                {
                    int nextByte = zipStream.ReadByte();
    
                    // End of Stream?
                    if (nextByte == -1)
                    {
                        finishedExactly = true;
                    }
                    else
                    {
                        byte[] newBuffer = new byte[buffer.Length * 2];
                        Array.Copy(buffer, newBuffer, buffer.Length);
                        newBuffer[read] = (byte)nextByte;
                        buffer = newBuffer;
                        read++;
                    }
                }
            }
            if (!finishedExactly)
            {
                byte[] final = new byte[read];
                Array.Copy(buffer, final, read);
                buffer = final;
            }
        }
    
        return buffer;
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in
I have some data strings that from one screen of my app that I
I have some data that won't printf.... echo works, but not printf There is
I have some data that I would like to visualize. Each byte of the
I have some data analysis code that processes an input file and outputs HTML
I have some data in my database this data updates everyday i want to
I have some data/helper classes defined which I use in several projects. These data
I have some data that lends itself to representation as a value and a
I have some Data coming out of my DB Model. What I want to
I have some data- attributes that I put into a table row tag. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.