Using Deflater and Inflater with JDK 1.1

Does anyone have an example using the classes Deflater and Inflater to decompress and compress data?
I get an "EOFException" when using the following code:
// compression
public Packet zipData(Packet packet)
// Create a new Deflater
Deflater def = new Deflater();
byte[] buf = new byte[packet.getData().length];
int offset = 0;
def.setInput(packet.getData(), offset, packet.getData().length);
def.finish();
offset = def.deflate(buf);
byte[] real_buf = new byte[offset];
System.arraycopy(buf, 0, real_buf, 0, offset);
packet.setData(real_buf);
return packet;
Any help will be greatly appreciated.
Thanks.

take a look at this techtip, may be it will be of some help to you
http://developer.java.sun.com/developer/TechTips/1998/tt0421.html#tip2

Similar Messages

  • Deflator and Inflator problem

    I use Deflator and Inflator to compress and decompress String for minimizing the size of the data to be sent in a network system.
    I wrote a class (DataCompressor.java) to do it.
    When i try to use it to compress and decompress within a single program (TestDataCompressor.java), it's all right.
    But when i try to compress a String in (DCClient.java), and sent the compressed String to (DCServer.java), there are exception in decompressing the compressed String
    My paltform is Windows2000 and JDK1.31
    Anyone know what is the problem i got?
    DataCompressor.java
    import java.util.zip.Deflater;
    import java.util.zip.Inflater;
    import java.util.zip.DataFormatException;
    import java.io.UnsupportedEncodingException;
    public class DataCompressor
    private Deflater DF = new Deflater(Deflater.HUFFMAN_ONLY,true);
    private Inflater IF = new Inflater(true);
    private int BUFFER_SIZE = 2048;
    private byte[] compressbytes;
    private byte[] decompressbytes;
    private String encoding = "UTF-16LE";
    public DataCompressor()
    compressbytes = new byte[BUFFER_SIZE];
    decompressbytes = new byte[BUFFER_SIZE];
    public DataCompressor(int bsize)
    BUFFER_SIZE = bsize;
    compressbytes = new byte[BUFFER_SIZE];
    decompressbytes = new byte[BUFFER_SIZE];
    synchronized public String compress(String inputString)
    int len;
    DF.reset();
    try
    DF.setInput(inputString.getBytes(encoding));
    DF.finish();
    len = DF.deflate(compressbytes);
    return new String(compressbytes,0,len,encoding);
    catch(UnsupportedEncodingException UEE)
    UEE.printStackTrace();
    return "";
    synchronized public String decompress(String inputString)
    int len;
    IF.reset();
    try
    IF.setInput(inputString.getBytes(encoding));
    len = IF.inflate(decompressbytes);
    return new String(decompressbytes,0,len,encoding);
    catch(UnsupportedEncodingException UEE)
    UEE.printStackTrace();
    return "";
    catch(DataFormatException DFE)
    DFE.printStackTrace();
    return "";
    synchronized void clear()
    DF.end();
    IF.end();
    DF = null;
    IF = null;
    compressbytes = null;
    decompressbytes = null;
    TestDataCompressor.java
    import java.io.*;
    public class TestDataCompressor
    public static void main(String[] args)
    String Data1 = "this is a test for data compression";
    String EnData1 = "";
    String DeData1 = "";
    DataCompressor DC = new DataCompressor();
    EnData1 = DC.compress(Data1);
    System.out.println("Out 1 :\n"+EnData1);
    DeData1 = DC.decompress(EnData1);
    System.out.println("Decom 1 :\n"+DeData1);
    DC.clear();
    DC = null;
    DCClient.java
    import java.io.*;
    import java.net.*;
    public class DCClient
    public static void main(String[] args) throws IOException
    Socket S = new Socket("127.0.0.1",9090);
    PrintWriter PW = new PrintWriter(S.getOutputStream(),true);
    String Data = "this is a test for data compression";
    String EnData = "";
    DataCompressor DC = new DataCompressor();
    EnData = DC.compress(Data);
    PW.println(EnData);
    System.out.println(EnData);
    System.out.println(EnData.length()+" chars sent");
    try
    byte[] D = EnData.getBytes("UTF-16LE");
    for(int i=0;i<D.length;i++)
    System.out.println(D+" : "+(char)D);
    catch(UnsupportedEncodingException UEE)
    UEE.printStackTrace();
    S.close();
    S = null;
    System.exit(0);
    DCServer.java
    import java.io.*;
    import java.net.*;
    public class DCServer
    public static void main(String[] args) throws IOException
    ServerSocket SS = new ServerSocket(9090);
    Socket S;
    BufferedReader BR;
    String message = "";
    DataCompressor DC = new DataCompressor();
    while(true)
    S = SS.accept();
    BR = new BufferedReader(new InputStreamReader(S.getInputStream()));
    while((message = BR.readLine())!=null)
    System.out.println(message);
    System.out.println(message.length() +" chars received.");
    try
    byte[] D = message.getBytes("UTF-16LE");
    for(int i=0;i<D.length;i++)
    System.out.println(D+" : "+(char)D);
    catch(UnsupportedEncodingException UEE)
    UEE.printStackTrace();
    System.out.println("Decompressed : "+DC.decompress(message));
    }

    This is a guess from a puurely cursory glance at your code. I thought I saw you using readline() to get compressed data off the wire. That is probably the wrong thing to do, as the data is not character data.

  • Using JDMK 4.2 with JDK 5.0

    I have an application that uses JDMK 4.2 and is currently built using JDK 1.4.2.
    I need to upgrade the JDK to JDK 5.0 which contains JMX 1.2. Can I continue using JDMK 4.2 with JDK 5.0, or must I upgrade the JDMK version to JDMK 5.0?

    Hi,
    You will need to use Java DMK 5.1 (or Project OpenDMK).
    Previous versions of the Java DMK used to embed their own implementation of JMX.
    The latest version of the Java DMK was designed to run on top of the JMX implementation embedded in the JDK.
    See:
    http://java.sun.com/products/jdmk
    http://docs.sun.com/app/docs/doc/816-7609
    http://opendmk.dev.java.net/
    Best regards,
    -- daniel

  • How do I use Qt and OpenGL with Visual Studio

    Hi! I mainly want to program in C++ and I want to use Qt and OpenGL with Visual Studio.
    I am currently revising C++ and later on i am going to start reading Qt and OpenGL. I have a background of
    Embedded firmware design(C and Assembly).
    The Visual Studio Version I have is 2013 ultimate. How do I use Qt and OpenGL with Visual Studio?
    Thanks
    Alexandros

    Hi ClassicalGuitar,
    The forum supports VS setup and installation. And your issue is not about the forum. I will move the thread to off-topic forum. Thanks for your understanding.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Using ConnBean and CursorBean with a Data Source

    Hi all,
    I',m making a web app. using the Jdev (RUP4) with OA Extension. I looked in the help menu under "About Data-Access JavaBeans and Tags". Here I found the following example, but for some stange reason I cannot get the setProperty to work.
    Example: Using ConnBean and CursorBean with a Data Source This following is a sample JSP page that uses ConnBean with a data source to open a connection, then uses CursorBean to execute a query.
    <%@ page import="java.sql.*, oracle.jsp.dbutil.*" %>
    <jsp:useBean id="cbean" class="oracle.jsp.dbutil.ConnBean" scope="session">
    <jsp:setProperty name="cbean" property="dataSource"
    value="<%=request.getParameter("datasource")%>"/>
    </jsp:useBean>
    <% try {
    cbean.connect();
    String sql="SELECT ename, sal FROM scott.emp ORDER BY ename";
    CursorBean cb = cbean.getCursorBean (CursorBean.PREP_STMT, sql);
    out.println(cb.getResultAsHTMLTable());
    cb.close();
    cbean.close();
    } catch (SQLException e) {
    out.println("<P>" + "There was an error doing the query:");
    out.println("<PRE>" + e + "</PRE>\n<P>"); }
    %>
    Does anyone know how to set the "Property" to a datasource and make it work?
    Best regards,
    MHCI

    There is no point-and-click (Import Data Source Metadata) way to use an LDAP server as a datasource. You have to use the Java Function provided on dev2dev. If you need help with it, please post here.
    - Mike

  • Configure CRS2008 to using AD and Kerberos with Java application servers.

    Hi All,
    I have configure CRS2008 to using AD and Kerberos with Java application servers. Domain Controller is installed on W2K3 Server. In addition, CRS2008 is installed on another W2k3 Server.
    I have create service account in domain controller: CMSACC
    I have create two user account: CRuser1 and CRuser2
    I have create domain group: CRSGroup
    After I had run the setspn in domain controller,I got the message at below:
    Registered ServicePrincipalNames for CN=CMSACC, OU=TEST, DC=BD, DC=com:
        BOBJCentralMS/BDMGTSRV.BD.com
    CMC Setting:
    AD Administration Name: BD\administrator
    Default AD Domain: BD.com
    Add AD Group(Domain\Group): secWinAD:CN=CRSGroup,OU=TEST,D=BD,DC=com
    Service principal name:BOBJCentralMS/CMSACCatBD.com
    I have create a WINNT folder in root directory.Moreover and save bcsLognin.conf and Krb5.ini at here.
    bscLogin.conf:
    com.businessobjects.security.jgss.initiate {
    com.sun.security.auth.module.Krb5LoginModule required;
    krb5.ini:
    [libdefaults]
    default_realm = BD.com
    dns_lookup_kdc = true
    dns_lookup_realm = true
    [realms]
    forwardable = true
    BD.com = {
    default_domain = BD.com
    kdc = BDMGTSRV.BD.com
    I have tested the Kerberos,using kinit CMSACCatBD.com password, and got error message at below:
    Exception: krb_error 41 Message stream modified (41) Message stream modified
    KrbException: Message stream modified (41)
            at sun.security.krb5.KrbKdcRep.check(KrbKdcRep.java:53)
            at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:96)
            at sun.security.krb5.KrbAsRep.getReply(KrbAsRep.java:486)
         at sun.security.krb5.KrbAsRep.getReply(KrbAsRep.java:444)
         at sun.security.krb5.internal.tools.Kinit.sendASRequest(Kinit.java:310)
         at sun.security.krb5.internal.tools.Kinit.<init>(Kinit.java:259)
         at sun.security.krb5.internal.tools.Kinit.main(Kinit.java:106)
    My problem is failed to logon CMC and infoview and got error message at below:
    Account Information Not Recognized: Active Directory Authentication failed to log you on. Please contact your system administrator to make sure you are a member of a valid mapped group and try again. If you are not a member of the default domain, enter your user name as UserNameatDNS_DomainName, and then try again.
    Actually, I am sucessful to logon Business View manager with CRuser1. However, I fail to logon CMC and infoview and got the above error. Have you any suggestion to solve this problem?
    Ken.

    if you can logon with client tools then that should be an indication that the service account running the CMS IS working! Good news.
    So the problem is likely with the java portion (krb5/bsclogin or java options)
    If the files are in c:\winnt\ (if not copy them there) and perform c:\program files\business objects\javasdk\bin\kinit username
    then enter and password/enter again
    Probably get the same message. To note in your krb5.ini all domain info must be in CAPS (the .com appears to be in lower case)
    kinit works with just the krb5.ini, java SDK and AD (removing BO config and the service account from the picture). Once that works if your java options are specified properly you should be able to login to CMC/infoview.
    also 1 last point. Add udp_preference_limit = 1 to the krb5 lib defaults section
    libdefaults
    default_realm = BD.com
    dns_lookup_kdc = true
    dns_lookup_realm = true
    udp_preference_limit = 1
    Regards,
    Tim

  • How to use audio and mic with multipoint server with out it crashing on you

    how to use audio and mic with multipoint server with out it crashing on you when i use them to make calls thru my station (zero client) at the same time it crashes on me and i need to restart the multipoint is there a setting i may have mist that enable's
    them to work at the same time and if posible can i use a non USB device 

    Look for "Single Sign-on Using Kerberos in Java" in google or on Sun's web site. Maybe this paper will help you.
    Claude

  • How to use "start" and "duration" with HLS stream

    Hi all,
    is it possible to use "start" and "stop" with HLS stream like rtmp stream?
    If yes, how?
    thanks in advance.

    Hi,
    This is completely player side fucntionality you are asking for. However, I guess default player that comes on safari (iPad), quicktime has the player timeline with stop and start option. But if not, you can create your custom player using exposed api of AVPlayer. Check-out AVPlayer api's.
    FMS, by nature of protocol will respect the request to get the data(in case of client-play-start)  and will not automatically push the data to the client if not asked for by the client (as in case of client-play-stop).
    Thanks

  • I use to use ichat and now with mountain lion i only have facetime. i try to keep in touch with my family thru the old ichat, will facetime work as easiely ? is it easy to connect with this app? thanks, gilbert

    I use to use ichat and now with Mountain Lion I only have FaceTime, will this work as easy as ichat? I try to keep in touch with my son and his family, he has a Mac also. I have never tried to do a video chat with my new Mountain Lion. I have set-up FaceTime and thought I would throw the question out before we try and get together.   Thanks,   Gilbert

    Ichat is now called Messages and is in your Applications folder.

  • Using iPhoto and editing with Photoshop Elements 4

    Hello
    I am new to Macs after many years using PC and I am struggling to set up my photo workflow. I shoot in RAW format and input into iPhoto from iPhoto I double click on the photo and which opens the RAW editor in Photoshop Elements. After making changes I open the file in Photoshop and then save as a TIFF.
    My problem is I do not see the changed and saved file in iPhoto and if I double click on the photo again it opens back up in the RAW editor not as a TIFF.
    Can any one point me in the right direction to solve this or is what I am trying to do not possible
    Thanks
    Grant

    Grant
    Welcome to the Apple Discussions.
    What you're trying to do is not possible.
    When you save as a TIFF you create a whole new file that needs to be imported into iPhoto anew. iPhoto will track an edit as long as you stay with the same file - so, edit your jpeg in PSE and use the 'Save' command and the change is reflected in iPhoto. However, you cannot Save RAW files, it's always a Save As... and so the resulting file has to be imported.
    Regards
    TD

  • How can I use undo and redo with run time menu?

    Hi..I try to built my own menu for graphic programming. How can I use undo and redo in labview with run time menu?

    filozof-
    During runtime, by default, LabVIEW has undo/redo data changes under the edit menu. This will undo/redo changes made to controls during runtime. If you want a more extensive undo/redo (custom for your application), you are going to have to do quite a few things
    1) Create a custom runtime menu (Edit>>RunTime Menu) and place your own undo/redo controls on it
    2) Keep an action history in your program
    3) Catch the Shortcut menu event for your custom undo/redo controls
    4) Reverse the last action in your histroy when you catch the event
    This method would allow you undo entire operations (like resize, move, or whatever kind of functionality you are building into your application) unstead of just undoing data changes.
    Xaq

  • Using MySql and PHP with Dreamweaver on a Mac

    Hello all,
    As always if the answers to these questions are obscenely
    obvious please humour me.
    I use XHTML and CSS in my websites and realise that it is
    time that I dabbled with SSI. So I've started using PHP.
    However, I have been following the installation directions of
    MySql and am running into problems. I am installing the relavent
    software and am then unable to find it on my Mac, the startup files
    are there but the actual MySql data appears to not be installed
    despite my computer telling me it is...... I am using a G3 running
    OSX 10.4 is this good enough? I noticed talk of needing a PowerPC
    or Intel mac. Is this the case?
    Also, would I need MySql installed on my actual computer if
    the my servers have it already? And does Dreamweaver 8 have both of
    these programs installed as standard?
    If you could help out I would be very appreciative as I would
    like to learn this stuff and I appear to be struggling at the
    outset....
    Cheers
    M.A

    M.A.Wilson wrote:
    > However, I have been following the installation
    directions of MySql and am
    > running into problems. I am installing the relavent
    software and am then unable
    > to find it on my Mac, the startup files are there but
    the actual MySql data
    > appears to not be installed despite my computer telling
    me it is...... I am
    > using a G3 running OSX 10.4 is this good enough? I
    noticed talk of needing a
    > PowerPC or Intel mac. Is this the case?
    MySQL is a relational database management system that
    comprises a
    database server and several utility programs. Although you
    install it
    like any other program on a Mac, the similarity stops there.
    First, the point about PowerPC and Intel Macs is that there
    are
    different versions of the MySQL installer for each type of
    processor.
    I'm pretty sure that a G3 is OK, but you must choose the
    PowerPC version
    of MySQL, not the 64-bit or x86 (Intel Mac) version.
    Once you have installed MySQL, you need to drag the
    MySQL.PrefPane icon
    from the disk image onto your System Preferences. This
    installs a
    Preference Pane that enables you to start and stop MySQL. The
    Preference
    Pane has an option to start up MySQL automatically, but in my
    experience, it doesn't work on Tiger. You need to open the
    Preference
    Pane, and click Start MySQL Server each time you start your
    computer.
    The best way to work with MySQL is to use a graphical
    interface, such as
    phpMyAdmin. As Osgood has mentioned, I have written a book
    about PHP and
    Dreamweaver, which goes into all the necessary details. It's
    also very
    Mac-friendly with separate instructions where necessary for
    PC and Mac.
    More details here:
    http://foundationphp.com/dreamweaver8/
    David Powers
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    http://foundationphp.com/

  • Installation sequence using PS7 and PS7 with SRA

    Our implementation architecture has three network zones i.e., Internet zone, SSN and data zone. We have two solaris machines. Each machine has one global and three local zones. Every machine zone has a iDM product installation. We did installation in following sequence
    1. DS on M1Z1
    2. AM on M1Z2
    3. IM on M1Z3
    Everything works here as expected.
    We have received PS7 and PS7 with SRA support bits from Sun.
    Can you please let us know which bits to use to complete following installation
    4. PS on M2Z1
    5. SRAG on M2Z2
    6. rewrite on M2Z3
    Do you have any documentation on installation of SRAG and rewrite on different machine and these machines does not have portal server installation.

    Portal server also requires DS and AM. So, I assume that you are going to point to the instances on M1 when you install portal.
    You also will need to install DS on the SRA machine. This directory is only needed during installation. Once things are up and running, then you can disable it.
    Start by installing Portal and make sure you install the SRA Core package. You must select this when you install portal the first time because the installer will not let you add it later. This is a known bug.
    Then, install the SRA Gateway component following these directions:
    http://docs.sun.com/app/docs/doc/819-3027/6n59bv1ne#hic
    These instructions are not entirely correct. Specifically, install everything in "Configure Now" mode.
    I don't know about installing Rewriter Proxy on a separate machine. I have not done this yet. Although it is a supported configuration.
    HTH,
    Jim

  • Runtime.exec() - using cp and files with spaces on unix

    I'm using the Runtime.exec method to copy files in a unix environment. This works fine until there is a file where the name has spaces in it. I've read the article on the pitfalls of using runtime and how it breaks a string on white spaces and this is what is happening. I've also found another topic that was having the same problem, but they were using /usr/bin/dos2unix. I've tried putting quotes around the filename, but it still breaks on the first space. Any suggestions on how to get around this or another way of doing this would be greatly appreciated.
    An example of the os command string is:
    /usr/bin/cp /tmp/file with space.doc /docs
    Thanks!

    Hi!
    Well I dont have any Sun machine right here to try this but in windows It works great.
    Have you tried something like this ?
    import java.io.*;
    public class OSCopy {
        public static void main(String[] args) {
            try {
                String space = " ";
                String copycmd = "E:\\cp.cmd";
                String source = "E:\\File with space.txt";
                String destination = "E:\\tmp";
                String cmd = copycmd + space + "\"" + source + "\"" + space + destination;
                System.out.println("cmd: " + cmd);
                Runtime runtime = Runtime.getRuntime();
                Process copy = runtime.exec( cmd );
                BufferedReader reader = new BufferedReader( new InputStreamReader( copy.getInputStream()) );
                String line = null;
                while( (line = reader.readLine()) != null ) {
                    System.out.println( line );
            catch (Exception e) {
                e.printStackTrace();
    cp.cmd is a simple dos copy command
    copy %1 %2
    */good luck!

  • Delay when using doubletap and hold with bootcamp 5

    Hi,
    I just bought a 15" MBPro and discoverd a delay when I use doubletap and hold to scroll or to mark text or drag. Is this a know problem of the bootcamp trackpad driver?
    Hoping for answers
    Bye
    Michael

    I have the same problem, except that I'm using the Apple Trackpad in Windows 8 in Boot Camp on a 2012 iMac, so my guess is that the driver is to blame.

Maybe you are looking for

  • Windows 7 drivers - which are essential?

    I have found the Windows 7 drivers on the Tosh download site - there are 32 for my model (PLL20E). Can anyone give any advice on which of these are 'essential'? For info, I have downloaded and installed the following: BIOS update to 1.60 Bluetooth Mo

  • Incoming Payments Error

    Hi experts, I have a customer with version 2007 and when him try include a Incoming Payment with a payment meas Bank Transfer occurr this  erro bellow: I nvalid Code [Journal Entry - Rows - Account Code] [line:2], '999999' [Message 173-36]

  • Why is this happening? pixellated screen, not rebooting

    This all it is seem to do. Day and Night. Doesnt reboot, doesnt do anything else. Doesnt charge. Randomly this happened. Explain someone please?

  • Swap file in use after 12 minutes uptime

    Hi I noticed this a little bit of a strange behavior recently. Once I power my Mac up, the amount of free memory is around 1.34 GB, as I don't have many startup items. Then I launch Skype and torrent client (µTorrent or Transmission) and wait about 1

  • How to update iPod touch 4 Gen to current IOS? It is 3 years old and won't update past IOS 4.2.1.

    I had to restore my iPod when I bought a new computer and it won't update the IOS. iTunes tells me it is up-to-date, but all the apps say I need IOS 5. How can I update this? Thanks