473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Any C# equivalent of Java's Inflator class?

basically, I need to port this part of an app into C#:

byte[] data // some compressed data separated from a Stream
Inflater inf = new Inflater();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
inf.setInput(data, 0, data.length);
byte[] result = new byte[1024];

int resLen;
while ((resLen = inf.inflate(result)) > 0) {
buffer.write(result, 0, resLen);
}
inf.end();

I tried using SharpZipLib but they don't see to have a way to simplay call
inflate on a specific byte array, they have a filter Stream so it makes it
ore compicated to do what I wanted. And when I tried it, I got a "EOF not
found" tpye of error... I just used MemoryStream instead of the byte array as
the input, and wrote the data from my byte array into the MemoryStream.

any suggestions? thanks!
Apr 5 '06 #1
8 7368

"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
basically, I need to port this part of an app into C#:

byte[] data // some compressed data separated from a Stream
Inflater inf = new Inflater();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
inf.setInput(data, 0, data.length);
byte[] result = new byte[1024];

int resLen;
while ((resLen = inf.inflate(result)) > 0) {
buffer.write(result, 0, resLen);
}
inf.end();

I tried using SharpZipLib but they don't see to have a way to simplay call
inflate on a specific byte array, they have a filter Stream so it makes it
ore compicated to do what I wanted. And when I tried it, I got a "EOF not
found" tpye of error... I just used MemoryStream instead of the byte array
as
the input, and wrote the data from my byte array into the MemoryStream.

any suggestions? thanks!


Do the J# libraries have what you need? You should be able to call them
from C#.

And if that doesn't work, please let me know. I have a background task to
replace our use of SharpZipLib with J#'s zip classes, and if it won't work,
tell me now :-)
Apr 5 '06 #2

"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
basically, I need to port this part of an app into C#:

byte[] data // some compressed data separated from a Stream
Inflater inf = new Inflater();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
inf.setInput(data, 0, data.length);
byte[] result = new byte[1024];

int resLen;
while ((resLen = inf.inflate(result)) > 0) {
buffer.write(result, 0, resLen);
}
inf.end();

I tried using SharpZipLib but they don't see to have a way to simplay call
inflate on a specific byte array, they have a filter Stream so it makes it
ore compicated to do what I wanted. And when I tried it, I got a "EOF not
found" tpye of error... I just used MemoryStream instead of the byte array
as
the input, and wrote the data from my byte array into the MemoryStream.

any suggestions? thanks!


I think that you are mostly stuck with stream based deflaters. The .NET 2.0
support is also based on streams.
Apr 5 '06 #3
MrNobody <Mr******@discussions.microsoft.com> wrote:
basically, I need to port this part of an app into C#:

byte[] data // some compressed data separated from a Stream
Inflater inf = new Inflater();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
inf.setInput(data, 0, data.length);
byte[] result = new byte[1024];

int resLen;
while ((resLen = inf.inflate(result)) > 0) {
buffer.write(result, 0, resLen);
}
inf.end();

I tried using SharpZipLib but they don't see to have a way to simplay call
inflate on a specific byte array, they have a filter Stream so it makes it
ore compicated to do what I wanted. And when I tried it, I got a "EOF not
found" tpye of error... I just used MemoryStream instead of the byte array as
the input, and wrote the data from my byte array into the MemoryStream.

any suggestions? thanks!


Using a MemoryStream will let you port the code above directly to C# -
that's the only bit which is different, really.

I'd personally use an InflaterInputStream instead, but to make it a
straight port, just use a MemoryStream.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 5 '06 #4
Thanks to everyone for your replies

This is what I did when I ported to C#:

byte[] data // some compressed data separated from a Stream

// since we cant call inflate on a byte[] array we must use a MemoryStream...
MemoryStream memTemp = new MemoryStream();
memTemp.Write(data, 0, data.Length);

InflaterInputStream inf = new InflaterInputStream(memTemp);
MemoryStream buffer = new MemoryStream();
byte[] result = new byte[1024];

int resLen;
while ((resLen = inf.Read(result, 0, result.Length)) > 0) {
buffer.Write(result, 0, resLen);
}
inf.Close();

When I ran this though I get: "Unexpected EOF"
at
ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputBuffer.Fill()
at
ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputStream.Fill()
at
ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputStream.Read(Byte[] b, Int32 off, Int32 len)

So I stepped through the code both in Java and C# to see if I can find any
differences. The input data (in memTemp or the data byte array) is the right
length but when I looked inside I noticed in Java all the bytes were signed,
there were negative numbers, but while in C# there were no signed numbers.

How could I get around this? MemoryStream does not accept sbyte arrays...
Apr 5 '06 #5
Mike Schilling <ap@newsgroup.nospam> wrote:
And if that doesn't work, please let me know. I have a background task to
replace our use of SharpZipLib with J#'s zip classes, and if it won't work,
tell me now :-)


Out of interest, why? I know I'd rather have one library which ports a
single part of the Java library than be stuck with a dependency like
J#. Also, being open source, if you find a bug in it, you can fix it.

I'm not saying it's the wrong thing to do - I'm just interested in the
reasons.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 5 '06 #6
MrNobody <Mr******@discussions.microsoft.com> wrote:
This is what I did when I ported to C#:

byte[] data // some compressed data separated from a Stream

// since we cant call inflate on a byte[] array we must use a MemoryStream...
MemoryStream memTemp = new MemoryStream();
memTemp.Write(data, 0, data.Length);
You haven't reset the position within memTemp, so there's nothing to
read.

An easier way of doing things is:

MemoryStream memTemp = new MemoryStream(data);
So I stepped through the code both in Java and C# to see if I can find any
differences. The input data (in memTemp or the data byte array) is the right
length but when I looked inside I noticed in Java all the bytes were signed,
there were negative numbers, but while in C# there were no signed numbers.

How could I get around this? MemoryStream does not accept sbyte arrays...


The difference between signed and unsigned bytes isn't an issue in this
case.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 5 '06 #7
Ah, I see! Makes perfect sense now. I was writing to this MemoryStream and
the position was always at the end of the data I was writing, so when I
passed it to the Inflater it found no data!

Great, I passed the data in to the constructor this time instead and it
works like a charm now.

Thanks !
Apr 5 '06 #8

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike Schilling <ap@newsgroup.nospam> wrote:
And if that doesn't work, please let me know. I have a background task
to
replace our use of SharpZipLib with J#'s zip classes, and if it won't
work,
tell me now :-)


Out of interest, why? I know I'd rather have one library which ports a
single part of the Java library than be stuck with a dependency like
J#. Also, being open source, if you find a bug in it, you can fix it.

I'm not saying it's the wrong thing to do - I'm just interested in the
reasons.


We have an important customer that disapproves of open source, and their
money outargues your good sense.
Apr 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
<?php class SuperClass { var $mySuperClassVar; function SuperClass($myVar) { $this->mySuperClassVar = $myVar; echo "super class var = $myVar<p>"; }
4
by: Gregory W. Ernest | last post by:
I am new to Java programming and I was wondering if anyone can tell me the java equivalent to a cin>>...; that is normally used in c++. I want to get user input and automatically assign it to a...
3
by: Gabriel Cooper | last post by:
What is the python equivalent to java's toString()? When debugging I want to be able to basically be able to do this: print MyObjectInstance or print str(MyObjectInstance) and have it...
4
by: Jim H | last post by:
Does .NET have an equivalent to java's JMS messaging. I'm not a java programmer but as I understand it a java application can be setup to pass entire objects between processes. Is there some sort...
2
by: yaron | last post by:
Hi, for porting java to c# i need to know: What is the C#.NET equivalent for java.net.SocketAddress and java.nio.ByteBuffer ? Thanks.
0
by: donnet | last post by:
To those familiar with Java beans, question on how to do with ASP.NET: I come from J2EE and starting to learn ASP.NET and C#. I want to find a way to display a web form filled with data taken...
5
by: pelon | last post by:
Hey! I'm new to OO in PHP but somewhat familiar with this paridigm in JAVA.... So I was wondering if it is possible to have within a PHP script something equivalent to a main method as it is...
4
by: JT | last post by:
In .NET I have been using the TransactionScope class to wrap my unit tests into a transaction and roll back any database changes after I have completed my unit test. Now I am dealing with some...
6
by: mearvk | last post by:
Does C++ or C have something roughly equivalent to this: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html What I need is a way to quickly convert between decimal and binary and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.