Inflater/Deflater Question

Hi
I was lookign into the java.util.zip package utilities - Inflator and Deflator apis and I am bit confused abt their usage - Lets take the scenario where I want to compress a byte[] of data - Ideally I would expect an API to like
public byte[] compress(byte[] dataToCompress)
Strangely enough the Deflator api does not have this - instead it has - setInput(byte[] dataToCompress) and then int deflate(byte[] buffer) - How on the world I will know the buffer size if I dont know what the compressed data size will be?? .
If anyone has really used Deflater - pls let me know how they have got around this problem. OR If there is any other better way to do that pls let me know.
TIA
Anamitra

Disclaimer: I have never used the Deflator class and this is meant to be a hand-waving example, it is not meant to be 'good' code. By no means should you use this code for anything important. You need to understand the class before you actually use it. I am just showing you the basic idea. From looking at the API there is clearly much more than this needed to use the class correctly. I haven't even tried to compile this.
Do something to the effect of:
ArrayList bufferList = new ArrayList;
byte[] input = getInput();
Deflator deflator = new Deflator();
int bytesReturned;
deflator.setInput(input);
do {
   byte[] buffer = new byte[1000]
   bytesReturned = deflator.deflate(buffer);
   bufferList.add(buffer);
} while (bytesReturned == 1000)

Similar Messages

  • Deflater/Inflater Anomaly

    Wrote a small class to provide deflate and inflate functionality to other classes, ran a few files through it and found that the uncompressed file was one byte longer than the input file. That byte showed up as a "?" at the end of the utf-8 file. Why is this?
    Code:
    package com.sra.pipeline.compression;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.zip.Deflater;
    import java.util.zip.DeflaterInputStream;
    import java.util.zip.Inflater;
    import java.util.zip.InflaterInputStream;
    public class Compressor {
         private String input = "input/aabqirL4Ob.html";
         private String output = "output/aabqirL4Ob.html";
         private String input1 = "input/aabpKgL4Ob.html";
         private String output1 = "output/aabpKgL4Ob.html";
         public Compressor() {
              byte[] bytes = readFile();
              System.out.println("File len " + bytes.length);
              byte[] cbytes = compress(bytes);
              System.out.println("Compressed len " + cbytes.length);
              byte[] fbytes = inflate(cbytes);
              System.out.println("UNCompressed len " + fbytes.length);
              writeFile(fbytes);
         public byte[] readFile() {
              byte[] bytes = null;
              try {
                   File file = new File(input1);
                   bytes = new byte[(int)file.length()];
                   FileInputStream fis = new FileInputStream(file);
                   fis.read(bytes);
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
              return(bytes);
         public byte[] compress(byte[] bytes) {
              ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
              DeflaterInputStream dis = new DeflaterInputStream(bais);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              try {
                   while(dis.available() == 1) {
                        baos.write(dis.read());
              } catch (IOException e) {
                   e.printStackTrace();
              return(baos.toByteArray());
         public byte[] inflate(byte[] cbytes) {
              ByteArrayInputStream bais = new ByteArrayInputStream(cbytes);
              InflaterInputStream iis = new InflaterInputStream(bais);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              try {
                   while(iis.available() == 1) {
                        baos.write(iis.read());
              } catch (IOException e) {
                   e.printStackTrace();
              return(baos.toByteArray());
         public void writeFile(byte[] out) {
              try {
                   FileWriter fw = new FileWriter(new File(output1));
                   fw.write(new String(out, "utf-8"));
                   fw.close();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new Compressor();
    }Thanks for any ideas,
    Jim

         public Compressor() {
              byte[] bytes = readFile();Here you are reading the entire file into memory which is already a bad idea.
              byte[] cbytes = compress(bytes);At this point you have both the plaintext and the compressed data in memory at the same time which is now twice as bad.
                   bytes = new byte[(int)file.length()];Here you are assuming the file size fits into an int.
                   fis.read(bytes);Here you are ignoring the result of the read() method.
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
              }Here you are essentially ignoring these exceptions and returning a byte array full of nothing to the caller. It would make more sense just to let the exceptions be thrown out of the method and let the caller see and deal with them.
              ByteArrayInputStream bais = new ByteArrayInputStream(bytes);Here you are constructing an InputStream around the bytes you read from a FileInputStream. Why not just read directly from the FileInputStream here?
              DeflaterInputStream dis = new DeflaterInputStream(bais);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();And here you are writing to a ByteArrayOutputStream from which you are going to extract a byte array and write it to a FileOutputStream. Why not write directly to the FileOutputStream?
              try {
                   while(dis.available() == 1) {Here you are misusing the available() function. It is never guaranteed to return 1 and it is not intended to tell you when you've reached the end of the input. read() returns a sentinel value for that purpose. Use it. There are few if any correct uses of available() and this is certainly not one of them.
                        baos.write(dis.read());Here you are ignoring the possibility that the return value is the sentinel, so you're writing junk to the file.
              } catch (IOException e) {
                   e.printStackTrace();
              }See above re exception handling.
    All these remarks also apply to your inflate method.
                   FileWriter fw = new FileWriter(new File(output1));
                   fw.write(new String(out, "utf-8"));And here you are committing the worst error of all: you are using a Writer to write binary data.
    But the bottom line is that you haven't added any value to what the inflater/deflater input and output streams already provide. So throw this all away and use those. All this stuff can be reduced to new InflaterInputStream(new FileInputStream(...)) and new DeflaterOutputStream(new FileOutputStream(...)) and a couple of copy loops, which should look like this:
    int count;
    byte[] buffer = new byte[8192];
    while ((count = in.read(buffer)) > 0)
      out.write(buffer, 0, count);
    out.close();
    in.close();

  • Java.rmi.NoSuchObjectException with custom InputStream/OutputStream

    I'm experiencing a strange problem here...and have spent the night digging for an answer,
    but I don't see any...
    I am using a custom client/server socket factory, which works great until I return my
    custom In/Out streams from the custom Socket. I can return a BufferedInputStream
    wrapping the socket's InputStream, but if I write a subclass BufferedInputStream
    (and override no methods) I get the NoSuchObjectException...
    any ideas?
    public class BInputStream extends java.io.BufferedInputStream {
      private InputStream in = null;
      public BInputStream(InputStream in) {
        super(in);
        this.in = in;
    }

    What I am trying to do (and have done with the minor limitation that I cannot use
    custom streams to compress the RMI traffic...) is create a totally transparent proxy
    for RMI services.
    The Proxy object is for any Remote object. A Proxy is returned to the client
    containing a Remote Invoker that is called by the Proxy's InvocationHandler.
    Since this is for a known environment, there is no need for dynamic class loading,
    so the JVMs must all have the classes to talk to one another...
      A <---> B <---> CI want to, now, compress the A <--> B link, because it is over a saturated link, and
    a cursory look at the actual data tells me I can compress 300k, which is a standard
    transaction size (after pruning classpath entries from the clients), to around 40k
    (conservative estimate). Obviously, this is a huge improvement in any environment,
    but an especially appealing one considering the fact that this link slows, literally, to
    a crawl at times. I already have the inflate/deflate streams worked out as far as I can
    test them, so all I need to do is get past this current stumbling block and test the
    compression bits in an environment more representative of the deployment env.
    Anyway, that's the highest level goal :-)
    So, a question...to confirm what I believe I found earlier that led me into this bowl
    of noodles (really, it's not that bad, except that I can't debug the code once
    it wanders off into RMI land, which may indicate a problem in my design :-P)...
    [after some more time poking around to make sure I'm not asking a stupid
    question]
    It seems my spaghetti (the exporting of the Invoker inside of the InvocationHandler)
    is necessary for the transparency I desire. As it turns out, I know enough now to
    find useful information from google on this subject :-) That's some progress!
    It seems springframework has something exactly like the server half of my
    system, so I'm gonna take a look at that as I wind this day down.
    cheers.
    b

  • Accept-encoding "compress"

    Hello,
    I'm compressing xml responses using "gzip" and "deflate" for requests with Accept-encoding "gzip" or "deflate" (or both).
    The problem is that I have a client that only uses "compress" (and this is not "negotiable", he'll only send "accept-encoding=compress").
    Is this compression format supported in jdk 5? For gzip I use GZIPInput/Outstream, and for deflate I use Inflater/Deflater. But for compress? Maybe is a variant of Inflater/Deflater? Can anybody help me, please?
    Thanks,
    Joan.

    No, there's no support for compress in the public Java SE 5.0 API. The compress algorithm (LZW) was largely obsoleted 15-or-so years ago by algorithms like deflate that decode faster and compress better.

  • RollOver handlers issue

    Hello,
    I have stumbled across the following problem. In flex i have defined (mxml or actionscript, doesnt matter) a group which contains a rectangle kind shape (Spark Path) and a few buttons which are all instances of a self made button component. Note that the buttons are not children of the rectangle path inside the group but are, like the path itself, direct siblings of the group, in other words, the buttons and path are same level children nodes of the group. Visually speaking however, buttons are placed over the group so they overlap with it. The buttons have a rollover/rollout event handled in them which just displays/hides a label on bottom of the button.
    The problem is... i also added a rollover/rollout handlers on the path (i ve also put the path additionally inside a skinnableContainer so it can handle events). The effect simply scales the path in x and y directions so it kind of inflates/deflates on rollover/rollout.
    Now because the buttons are not children of this path, when i move the mouse over the path, it inflates, but when i move the cursor further inside the path and over a button the rollout for the path happens which i DONT want(and also rollover for the button, thats ok), the path should stay inflated while the user has the mouse anywhere inside its area.
    I also cant simply make the buttons children of the path, because they will scale along with the path, also not acceptable. Im sure this is a pretty common problem, i stumbled across it even when using pure actionscript, but i always somehow redesigned my interface because i couldnt deal with it properly.
    I also tried the hittesting functions and they arent much help in this situation, also event capture and bubbling as these are all separate events.
    Thanks for any reply.

    No, every button instance has its own handlers, and the skinnable container (holding the path) has the handlers, the group holding everything together doesnt have any. Looks something like this:
    <s:Group>
    ... some animate elements declarations
    ... some script
    <s:SkinnableContainer id="holder" rollOver="onPathRollOver(event)" rollOut="onPathRollOut(event)">
         <s:Path id="dock" data="L 0 90 L 300 90 L 390 0 Z" x="-390" y="-20">
              <s:fill>
                   <s:SolidColor color="0x000000" alpha="0.3" />
              </s:fill>
         </s:Path>
    </s:SkinnableContainer>
    <com:MainMenuButton id="btnCamera" x="11" y="10" ImageURI="art/icons/48_camera.png" Label="Video"/>     <------ each of these handles rollovers inside of them
    <com:MainMenuButton id="btnPhoto" x="53" y="10" ImageURI="art/icons/48_photo.png" Label="Panoramas"/>
    <com:MainMenuButton id="btnMap" x="119" y="10" ImageURI="art/icons/48_map.png" Label="Mini map"/>
    <com:MainMenuButton id="btnFullscreen" x="169" y="10" ImageURI="art/icons/48_fullscreen.png" Label="Full screen"/>
    <com:MainMenuButton id="btnQuit" x="237" y="10" ImageURI="art/icons/48_quit.png" Label="Exit"/>
    </s:Group>
    The path and buttons are not in a parent child relationship, but buttons sit on top of the path on stage.

  • Space between multiple objects

    Is there a way to alter the space between multiple objects without changing the objects themselves? You know, kind of like inflating/deflating a balloon with dots on the surface (yes, the dots would get bigger/smaller, but I think you get the idea). I've tried Transform>Move>Distance, and Effect>Distort & Transform>Transform>Move>Horizontal/Vertical, but both methods just moved all selected objects away from the origin point - no change to the space between objects. any ideas?

    ...you'd think there'd be an easier way...
    Are you talking about objects that already have equal spaces between them? If so, use the Distribute Spacing function in the Align palette. You can specify the desired horizontal/vertical distance between an array of objects.
    JET

  • GZIP using nio ByteBuffer

    In Java 1.4 CharsetEncoder/CharsetDecoder classes were added to encode/decode unicode to/from ByteBuffers to fully utilize the performance advantages of the nio package. Why didn't they do the same for GZIP compresssion/decompression? Does anyone know of a way to read/write a GZIP file using nio and compress/decompress to/from ByteBuffers instead of using GZIPInputStream and GZIPOutputStream?

    llschumacher wrote:
    That will work but it is not what I had in mind. I wish to offload compression/decompression to another thread. Basically what I am doing is reading byte buffers with one thread, queueing them to a second thread to decompress and then queueing the decompressed buffer to a third thread for Unicode Decoding. I also want to use 3 threads in reverse order to perform writes. I can do this with Unicode encode/decode using CharsetEncoder/CharsetDecoder classes because they deal directly with ByteBuffers. Your solution would require me to use the same thread for IO and compress/decompress.here you go...
    1) create a threadpool executor.
    2) inherit from and extend callables to read or write nio channel objects
    3) use Inflate/Deflate on byte[] for your needs.
    4) works for JCE code as well

  • _z_inflateInit_ referenced from symbol missing (zlib linking error)

    I am trying to compile a project that uses inflateInit, deflateInit, inflate, deflate, inflateEnd, deflateEnd, which are all from zlib.h... i know i am getting a linking error and it cannot find the implementation of these files. i have included libz.1.1.3.dylib within my project, i have tried including libz.dylib, i have also tried to put the
    OTHER_CFLAGS = -lz
    none of this has seemed to work. any help would be much appreciated ! ! !
    this is the definition for inflateInit and it calls zinflateInit which is also in zlib.h
    {#define inflateInit(strm) \
    inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
    ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
    const char *version, int stream_size));
    when i build my project, the errors i get are :
    z_inflateInit, referenced from:
    foo()
    zinflate , referenced from:
    foo()
    symbols(s) not found collect2: Id returned 1 exit status

    http://discussions.apple.com/thread.jspa?threadID=1445315&tstart=0 ?

  • Meanin of some terms

    <p>Hi    </p><p>      Can anyone please tell methe meaning of the terms inflated /deflated cubes and frozen cube,or tell me where I can read about it. I dont think users guideuses these terms.</p><p> </p><p>Thanks</p>

    <p>Hi , Frozen cube is the one where all the data will be freezed.That mean once we are done with the year end activity , we willclose the books furhter we won't update the books except we willread the books. So we will make the data in that cube to readonly</p><p> </p>

  • Deflater and Inflater again!

    Hi All
    This is in continuation of the thread
    http://forum.java.sun.com/thread.jsp?thread=389668&forum=4&message=1683180
    I am working on a similar problem. We need compress and decompress some messages which are Java 'String's. I have explored this and many other solutions to implement this in Java using the zip package but nothing has worked so far.
    My specific question here is related to the code snippet given below. It doesnt work with String str but works fine with String str2. Can someone please explain to me why?
    Here's the exception trace that I get when I use String str
    /*****************************EXCEPTION TRACE BEGINS*****************************************/
    oversubscribed dynamic bit lengths tree
    java.util.zip.DataFormatException: oversubscribed dynamic bit lengths tree
    at java.util.zip.Inflater.inflateBytes(Native Method)
    at java.util.zip.Inflater.inflate(Unknown Source)
    at EncodeDecodeExample.<init>(EncodeDecodeExample.java:52)
    at EncodeDecodeExample.main(EncodeDecodeExample.java:75)
    /*****************************EXCEPTION TRACE ENDS*****************************************/
    Please note that, the exception message changes to "java.util.zip.DataFormatException: incorrect data check" if String str3 is used instead of String str in the line marked "/***********change string here***********/".
    Here's the code snippet
    /*****************************CODE BEGINS*****************************************************/
    import java.util.zip.*;
    import java.io.*;
    import java.lang.reflect.Array;
    public class EncodeDecodeExample
         public EncodeDecodeExample()
              try{
                   // encoding the string into byte
                   String str = "Please encode this string neelesh abcdefghp ijklmnop";
                   String str2 = "Please encode this string neelesh";
    String str3 = "Please encode this string neelesh Please encode this string neelesh Please encode this string neelesh abcdefghp ijklmnop";
                   byte[] bt = str.getBytes(); /***********change string here***********/
                   // compressing the bytes
              int initialSize = 10;
                   byte[] output;
                   Deflater deflater;
                   int datalen;
                   do{
                        output = new byte[initialSize];
                        deflater = new Deflater();
                        deflater.setInput(bt);
                   deflater.finish();
                        datalen = deflater.deflate(output);
                        if(datalen == initialSize){
                             initialSize *= 2;
                        else{
                             break;
                   }while(true);
                   String tempString = new String(output, 0 , datalen);
                   byte[] tempBt = tempString.getBytes();
                   // decompressing the bytes
                   Inflater inflater = new Inflater();
                   inflater.setInput(tempBt, 0, Array.getLength(tempBt));
                   byte[] result = new byte[4000];
                   int reslen = 0;
                   try{
                        reslen = inflater.inflate(result, 0, 80);
                   catch(DataFormatException e)
                        System.out.println(e.getMessage() );
                        e.printStackTrace();
                   inflater.end();
                   // decoding bytes to a String
                   String outputString = new String(result, 0, reslen);
                   System.out.println(outputString);
              }catch(Exception e){
                   System.out.println(e.getMessage() );
                   e.printStackTrace();
         public static void main(String args[])
              new EncodeDecodeExample();
    /*****************************CODE ENDS*****************************************************/

    HI All
    Extremely sorry for the goof up, please refer to this piece of code intead of the one in the earlier posting, thanks
    Neelesh
    /*****************************CODE BEGINS*****************************************************/
    import java.util.zip.*;
    import java.io.*;
    import java.lang.reflect.Array;
    public class EncodeDecodeExample
         public EncodeDecodeExample()
              try{
                   // encoding the string into byte
                   String str = "Please encode this string neelesh abcdefghp ijklmnop";
                   String str2 = "Please encode this string neelesh";
                   String str3 = "Please encode this string neelesh Please encode this string neelesh Please encode this string neelesh abcdefghp ijklmnop";
                   byte[] bt = str.getBytes(); /***********change string here***********/
                   // compressing the bytes
                   int initialSize = 10;
                   byte[] output;
                   Deflater deflater;
                   int datalen;
                   do{
                        output = new byte[initialSize];
                        deflater = new Deflater();
                        deflater.setInput(bt);
                        deflater.finish();
                        datalen = deflater.deflate(output);
                        if(datalen == initialSize){
                             initialSize *= 2;
                        else{
                             break;
                   }while(true);
                   String tempString = new String(output, 0 , datalen);
                   byte[] tempBt = tempString.getBytes();
                   // decompressing the bytes
                   Inflater inflater = new Inflater();
                   inflater.setInput(tempBt, 0, Array.getLength(tempBt));
                   byte[] result = new byte[4000];
                   int reslen = 0;
                   try{
                        reslen = inflater.inflate(result);
                   catch(DataFormatException e)
                        System.out.println(e.getMessage() );
                        e.printStackTrace();
                   inflater.end();
                   // decoding bytes to a String
                   String outputString = new String(result, 0, reslen);
                   System.out.println(outputString);
              }catch(Exception e){
                   System.out.println(e.getMessage() );
                   e.printStackTrace();
         public static void main(String args[])
              new EncodeDecodeExample();
    /*****************************CODE ENDS*****************************************************/

  • Inconsistent compression with Deflater/Inflater

    I try to (un)compress some data using the (In)Deflater class. I want to have GZIP compression, so I set nowrap to true. The javadoc for the Inflater class says something mysterious like "Note: When using the 'nowrap' option it is also necessary to provide an extra "dummy" byte as input. This is required by the ZLIB native library in order to support certain optimizations." What does that mean?
    I have written a test program in which I check if the original data and the uncompressed data is the same. When I run this program I get about 2 errors per run (Inflater not finished).
    Any ideas?
    import java.util.zip.DataFormatException;
    import java.util.zip.Deflater;
    import java.util.zip.Inflater;
    public class ZipTest
        private static byte[] createTestBytes(int size)
            byte[] result = new byte[size];
            for (int i = 0; i < result.length; i++)
                // result[i] = (byte)(i % 256);
                // result[i] = 0;
                result[i] = (byte)(Math.random() * 256);
            return result;
        public static void testGZIP()
            byte[] data = createTestBytes(DATA_SIZE);
            Deflater def = new Deflater(5, true);
            def.reset();
            def.setInput(data);
            def.finish();
            byte[] comp = new byte[MAX_DATA_SIZE_COMP];
            int compBytes = def.deflate(comp);
            byte[] decompData = new byte[DATA_SIZE];
            Inflater inf = new Inflater(true);
            inf.reset();
            inf.setInput(comp, 0, compBytes);
            int decompBytes = 0;
            try
                decompBytes = inf.inflate(decompData);
            catch (DataFormatException exp)
                System.err.println(exp);
            if (inf.finished() == false)
                System.err.println("Inflater not finished "+DATA_SIZE+" "+inf.getRemaining());
            int nDiffs = 0;
            for (int i = 0; i < DATA_SIZE; i++)
                if (data[i] != decompData)
    nDiffs++;
    if (nDiffs > 0)
    System.err.println(nDiffs + " diffs");
    public static int DATA_SIZE = 16080;
    public static int MAX_DATA_SIZE_COMP = (int)(DATA_SIZE * 1.5d);
    public static Deflater def = new Deflater(5, true);
    public static Inflater inf = new Inflater(true);
    public static void main(String[] args)
    for (int i = 0; i < 5000; i++)
    DATA_SIZE = (int)(Math.random()*(1024*64));
    MAX_DATA_SIZE_COMP = (int)(DATA_SIZE * 1.5d)+1024;
    testGZIP();
    System.out.println("Finished.");

    Has nobody an idea why data compressed with Deflater(5,true) cannot always be decompressed by Inflater(true)? What am I doing wrong?
    Thanx
    Ulrich

  • File inflate and deflate problem

    i have a code that deflates a file "first.txt".But when run it is not printing the proper message written after deflating code.However the deflated file is generated "first.txt.dfl"
    import java.io.*;
    import java.util.zip.*;
    public class DirectDeflector
    public final static String DEFLATE_SUFFIX=".dfl";
    public static void main(String args[])
         Deflater def=new Deflater();
         byte[] input=new byte[1024];
         byte[] output=new byte[1024];
         try
         FileInputStream fin=new FileInputStream("first.txt");
         FileOutputStream fout=new FileOutputStream("first.txt"+DEFLATE_SUFFIX);
         while(true)
              int numRead=fin.read(input);
              if(numRead==-1)
    def.finish();
    while(!def.finished())
         int numCompressedBytes=def.deflate(output,0,output.length);
         if(numCompressedBytes>0)
              fout.write(output,0,numRead);
    break;
              else
                   def.setInput(input,0,numRead);
                   while(!def.needsInput())
                        int numCompressedBytes=def.deflate(output,0,output.length);
                        if(numCompressedBytes>0)
                             fout.write(output,0,numCompressedBytes);
         fin.close();
         fout.flush();
         fout.close();
         def.reset();
         System.out.println("File deflated!!");
    }catch(Exception e )
         System.out.println(e.getMessage());
    **But instead of printing "File deflated!!",it is printing null.
    Again when i inflate the and write it to another file it is not working..Here is the code..
    import java.io.*;
    import java.util.zip.*;
    public class DirectInflator
    public static void main(String args[])
         Inflater inf=new Inflater();
         byte[] input=new byte[1024];
         byte[] output=new byte[1024];
         try
              FileInputStream fin=new FileInputStream("first.txt.dfl");
              FileOutputStream fout=new FileOutputStream("firstread.txt");          
              while(true)
                   int numRead=fin.read(input);
                   if(numRead!=-1)
                        inf.setInput(input,0,numRead);                    
                   int numDecompressed=0;
                   while((numDecompressed=inf.inflate(output,0,output.length))!=0)
                   fout.write(output,0,numDecompressed);     
                   if(inf.finished())
                        break;
                   else if(inf.needsDictionary())
                        System.err.println("Dictionary required!!");
                        break;
                   else if(inf.needsInput())
                        continue;
              fin.close();
              fout.flush();
              fout.close();
              inf.reset();
              System.out.print("Inflation successful!!");
         }catch(DataFormatException e)
              e.getMessage();
         catch(IOException e)
              e.getMessage();
         catch(Exception e)
              e.getMessage();
    **plz help

                int numRead=fin.read(input);
                if(numRead==-1)
    def.finish();Seems to be an 'else' missing here.
          int numCompressedBytes=def.deflate(output,0,output.length);int numCompressedBytes=def.deflate(output,0,numRead);
          if(numCompressedBytes>0)
               fout.write(output,0,numRead);
    fout.write(output,0,numCompressedBytes);
                elseWhat is supposed to be happening in the following block I have no idea.

  • 3d sphere inflating and deflating

    I am trying to build a simple VI which when given a duration, will display a sphere increasing in size/scale and then decreasing in size/scale for the same duration.
    Imagine this to be like a baloon that is inflating and deflating continuously. The inflatrion shuld start from 0.5 scale to 1 and then it should deflate in equal number of steps from1 down to 0.5
    I have tried to implement this  using simple logic but the 3d display doesnt work correctly . Not sure if my logic is right.
    Also, I have only managed to do a 0 to 1 scale increase instead of a 0.5 to 1
    Code attached.
    Attachments:
    3d display.vi ‏18 KB

    Hi Jaspal,
    I attached a version of your VI in 8.6 that does what I think you'd like.
    There were 2 problems with your VI that I saw, the first was you wired "N" from the loop instead of "i".  So you were always comparing 20>9 and never getting to your other case.
    The other is it looks like you were splitting the 3D Picture Control reference and expecting it to treat all of your 3D Picture Controls independently.  With a reference any rotations/scales/translations will apply to the scene on that reference and all controls wired to it.
    Attachments:
    3d display.vi ‏14 KB

  • 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

  • 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.

Maybe you are looking for

  • Using java beans in jsp using tomcat

    hi i have made a form to enter user first name and last anme with html and then i have made a value javabean in which i want to store the information filled bu user. i want to display the information stored in java bean in jsp page i have made the fu

  • Internet sharing in a small coffee house

    I have a friend who has a small coffee house. The place is equiped with a DSL modem and a BEFW11S4 wireless router. Currently the router is wide open and anyone can use the connection. We would like to change things so that the wireless connection ca

  • Events Between APO & BW

    Hi Friends Good Morning, Please give me the solution on the following proble. One process chain is there in APO system, that will execute in APO system only, and I have a BW system, once the process chain executed successfully in APO system, immediat

  • Parental controls missing

    Just noticed that the parental contols is missing. The tab is there in system prefs and I've tried 2 different admin accounts but when selected all I get is a blank area with Parental Controls across the top, no tabs nothing any ideas!!!!!! I'm using

  • Error Using SqlServer SMO.

    Hi,  I want to transfer database objects from One Database to other including all keys that exists between tables using SqlServer SMO .I had tried with MSDN Code but i am facing with some error i.e., ERROR : errorCode=-1073548784 description=Executin