Using GZIP streams to compress

First time poster, long time reader
I'm trying to write some serializable objects (ArrayLists) to file, but I wanted to compress them first. The GZIP stream isn't doing anything, even when it should. How should I be using it? Thanks if you can help
     public void save( String filename )
          try {
               File file = new File( filename );
               FileOutputStream outStream = new FileOutputStream( file );
               GZIPOutputStream zipOut = new GZIPOutputStream( outStream );
               ObjectOutputStream out = new ObjectOutputStream( zipOut );
               out.writeObject( xList );
               out.writeObject( yList );
               out.writeObject( list );
               out.close();
          } catch (IOException e) {
               System.exit( 1 );
     }

On another note, what is the best way to turn a byte
array into an int array and vice versa?Check out the ByteBuffer class:
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
IntBuffer intBuffer = byteBuffer.asIntBuffer();
// then you can do:
int i = intBuffer.get(i);Hope this helps.

Similar Messages

  • Is it possible to compress SWF files using gzip?

    I am using gzip for all the files of my server but my swf doesn't seem to be getting compressed also "swfobject_modified.js" used by the SWF file doesn't get compressed as well, whereas other .js files are getting compressed. Any suggestions ?

    For quite a while swfs are (by default) (g)ziped when published. You can change that under the publish-settings using the flash tab. Regarding the swfobject, I think that the code is very size optimized, whereas your regular run of the mill self-made .js is mostly optimized for readability.
    M

  • Compress a signed message using gzip

    Hi,
    I need to compress the signed message which is an object using gzip compression and later on decompress it. How can I do this? Do I need to write the object to a file in order to compress it? Can I do this without writing to a file?
    Thanks

    http://forum.java.sun.com/thread.jsp?thread=324835&forum=31&message=1317133

  • XML compression using GZip (Urgent)

    Hi ,
    I am compressing XML on the fly using GZip and storing it in a Database. When required we uncompress using same utility and everything works fine until we encounter a large XML (more than 1200 Bytes). What happens then is XML is Truncated and final few tags are missing in the uncompressed XML. I am not sure if the Compression is truncation or the Uncompress ....
    Please look into the code sinppets and lemme know if you find any bugs there....
    CompressMethod............
    String someXML = "....long xml....";
    try {
    int length = someXML .trim().length();
    ByteArrayOutputStream baos =
    new ByteArrayOutputStream(length);
    ByteArrayInputStream bis = new ByteArrayInputStream(filename.trim().getBytes());
    GZIPOutputStream gos = new GZIPOutputStream(baos);
    byte[] buffer1 = new byte[9092];
    int bytesRead;
    while ((bytesRead = bis.read(buffer1)) != -1) {
    gos.write(buffer1, 0, bytesRead);
    bis.close();
    gos.close();
    return baos.toByteArray();
    For Uncompressing ..................
    ByteArrayInputStream bai = new ByteArrayInputStream(filename);
    byte[] buffer = new byte[9092];
    GZIPInputStream gos =
    new GZIPInputStream(bai);
    gos.read(buffer,0,buffer.length);
    gos.close();
    orig = new String(buffer,"iso-8859-1");
    Any Help at the earliest is appriciated and REWARDED !!!!!!!

    I'm not quite sure why you are doing some of the things your are. It might be your haste in getting a code "snippet" to show.
    String someXML = "....long xml....";...
    int length = someXML .trim().length();...
    ByteArrayInputStream(filename.trim().getBytes());Is your xml really in a known String like "someXML" or is it being read from the file represented by "filename"? If it is in a string and you wish to find the length of the trimmed article, then trim it first and reference only the trimmed String from then on. If you take the length of a temporarily trimmed String and then use the non-trimmed String you may be cutting data off of the end.
    Also, if your xml is in a String there is no need to have a read loop. Just write your byte array in one call.
    The length of the trimmed string is the only thing that I see that could cause your loss of data.

  • How to use GZip propperly?

    I have been trying to make a program that zips a whole file at a time, I heard Gzip can do it, but the Java help thing does not show how to implement GZip
    here is where I am so far am I going in the write direction?
    Also is there a good Java book, with alot of example code in it?
    import java.io.*;
    import java.util.zip.*;
    public class Compress {
    public static void main(String[] args) throws IOException {
    File dirf;
    File filef;
    File zipf;
    Final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    //next 3 code segments gets the directory, original file and zip file names
    System.out.print("Enter in the directory of the file here:> ");
    dirf = new File(reader.readLine());
    String directory = dirf;
    System.out.print("Enter in the name of the file to be zipped here:> ");
    filef = new File(reader.readLine());
    String files = filef;
    System.out.print("Enter in the enter in the name of the zip file here:> ");
    zipf = new File(reader.readLine());
    String zip = zipf;
    //creates the zip file in the same directory as the old file
    File dir = new File(directory);
    File zipper = new File(dir, zip);
    zipper.createNewFile();
    //primes for input of the zip file from old file
    GZIPOutputStream zipfile = new ZipOutputStream(
    new FileOutputStream(zipper));

    Yup, pretty much. (You could always accept the filenames from the command line using the arg[] parameter on main).
         public void zipAFile(File source, File target) throws IOException, FileNotFoundException
              FileInputStream fis = new FileInputStream(source);
              FileOutputStream fos = new FileOutputStream(target);
              GZIPOutputStream gzos = new GZIPOutputStream(fos);
              byte[] buffer = new byte[2048];
              int read = fis.read(buffer);
              while (read == 2048)
                   gzos.write(buffer);
                   read = fis.read(buffer);
              gzos.write(buffer, 0, read);
              // The next step is VERY important.  If you do not flush the buffer
              // on the inner (gzip) stream, the outer (file) stream will get
              // closed before it gets the last buffer of data.
              gzos.close();
              fis.close();
              fos.close();
         }Cheers!

  • Socket + GZip Stream + Object Stream problem

    Hello,
    I've been having a problem with my threaded networked application. I want to send GZipped Objects over a socket, but the ObjectInputStream constructor blocks. I understand that it is waiting for header information from the corresponding ObjectOutputStream. I am sure that the socket connection has been established, and the ObjectOutputStream is constructed before the ObjectInputStream on the other end. The header information never seems to get to the other end.
    If I remove the Gzip filter stream, everything works great. I'm thinking that the Gzip stream is buffering the 4 bytes of header info, waiting for more data before actually compressing anything. I've tried flushing everything, to no help. I've tried finish()ing the Gzip stream, but that means I can't send my object payload. I've checked the buffers of all the stream objects and see the Object Stream's header in its buffer, but never seems to get into the GZIPOutputStream's buffer.
    Has anyone successfully used Object Stream > GZIP Stream > Socket Stream before?
    I'm not interested in examples that use file streams, since I get the impression that Gzip works fine with those (and maybe even designed only for those, not for sockets).
    Thanks for any help.
    Dave C

    Thanks. I see what I'm doing differently now. I was trying to send multiple objects over the gzip stream, not 1 at a time, finish(), and construct a new Gzip and Object output stream.
    Seems to work with a ByteArrayOutput/InputStream, now to try with a socket..

  • HT201317 If I don't want to use photo stream, can I still upload a bunch of photos to iCloud and then share them with people who do not have iCloud?

    If I don't want to use photo stream, can I still upload a bunch of photos to iCloud and then share them with people who do not have iCloud?

    iCloud provides a simple gallery in the form of 'Photo Journal' - uploading of photos from iPhoto to web pages hosted on iCloud, but only from iOS devices; and the photos are compressed to a size adequate for online viewing but are not available in full resolution as with the old MobileMe Gallery. Apple have provided a sample album here.
    There are various other photo gallery services which you may find preferable: some of them are examined here -
    http://rfwilmut.net/missing4

  • How can i use shoutcast streams on windows phone?

    I have an idea to make an application but i don't know how to use shoutcast streams in windows phone ? Is there any API or something that i need to fallow?
    Alican

    At the moment Shoutcast audio streams are not supported natively in Windows Phone. You will need to write a self implementation of IMediaStreamSource to parse the audiostream and also handle the http connections to the streaming server.
    Another solution is to use a third party implementation such as www.jupitersdk.com.
    It offers a well documented API, is easy to integrate and use into your project and there is a trial version for testing purposes.
    Jupiter Sdk has successfully been used in several RadioStreaming apps which can be found in the Windows Phone Store. By the way, it allows not only to play Shoutcast and Icecast audiostreams in Windows Phone 8.1, but also to retrieve the stream metadata (i.e.
    current Title and Artist), among other interesting features.
    Disclaimer: I am a member of the Jupiter Sdk Development Team. For information and support you can use the contact form at www.jupitersdk.com

  • How to use one stream by two or more threads?

    Hey guys,
    i have got a little problem and do not know how to solve it. i hope you guys can are able to help me.
    i have opened a bluetooth socket connection. now i want to use these streams by three or more threads. one thread should only read from an input stream. the other threads are supposed to write on the ouput stream.
    (I think) I am only able to open one stream in each direction.
    How do I realize the use of the output stream by two indepent threads?
    thanks for your help!

    thank you for the hint!
    i will search it or do you know a good tutorial?

  • How do you view photos through windows explorer without using photo stream?

    I updated to the iOS6 and I can no longer view and download photos to my PC through windows Explorer.
    I do not really want too use photo stream and or the iCloud at this time...
    It now appears Apple is now forcing you to use the iCloud to get pictures off of your iphone...
    I dont want this, I want to do it manually, without the iCloud. 
    Help Please.

    I run ios6 and when I connect my iphone to windows it show up as a camera in my computer this have been the case since the first iphone when I click on the camera I can navigate to the folders to where my pictures and videos are stored only the ones taken on the iphone mind you again something don by design and worked like that forever

  • TS3989 New MacAir but  photostream does not work.  Message though everything is on. "In order to use Photo Stream, you have to be signed into your iCloud account in System Preferences." And,

    New computer but Photostream does not work.  I am signed into my account but get the following message:  In order to use Photo Stream, you have to be signed into your iCloud account in System Preferences.  I go to system preferences and then get a message that says that my account cannot be accessed.  However, I am using my icloud account for email and other items and it works fine.  Any thoughts?

    Are you getting this messages in iPhoto? If so try the following (again?):
    Log out of iCloud in the System/iCloud preference pane and disable Photo Stream in iPhoto's Photo Share preference pane.  Then log back in and re-enable, respectively.  That should jump start Photo Stream.
    OT

  • I have just bought an iMac, and when I had my PC I had all my mp3 music on external hard drive and used to stream using software called ps3 server and tveristy which used to pick up on my Roberts radio via network wi fi hiw do I get iMac to do it

    I have just bought an iMac, and when I had my PC I had all my mp3 music on external hard drive and used to stream using software called ps3 server and tveristy which used to pick up on my Roberts radio via network wi fii and on my iPad via AirPlay. How can I do the same with iMac as this software isn't compatible

    To install apps from developers Apple doesn't recognize go to Security and Privacy in the System Preferences and change Allow apps downloaded from anywhere

  • HT4906 I just upgraded iphoto, but it is version 7.1.5 (and called iPhoto 8). Do I have to pay for iPhoto 9 in order to use photo stream?

    I just upgraded iphoto, but it is version 7.1.5 (and called iPhoto 8). Do I have to pay for iPhoto 9 in order to use photo stream?

    To use Photo Stream, you will need iPhoto 9.2 at least. This is a major upgrade from iPhoto 7.1.5 and you will have to buy it.
    See:
      iPhoto and Aperture: Using Photo Stream
    Regards
    Léonie

  • HT4906 why cant i use iPhoto stream with mountain lion

    it wont let me check the box with my macbook to allow me to use photo stream
    how can i fix this

    upgrade iPhoto to the required version - what version of iPhoto do you have?
    see  http://www.apple.com/icloud/setup/mac.html for information for requirements
    LN

  • Can't share photos using photo stream in iCloud. File is always blank.

    Can't share photos using photo stream in iCloud. File is always blank.

    Hello desert_dweller5,
    It sounds like you art trying to access a Shared Photo Stream, but you do not have one of the devices to enable your Apple ID as an iCloud account.  The following article provides information on how Shared Photo Streams work:
    iCloud: Photo Stream FAQ
    http://support.apple.com/kb/HT4486
    The article states that for privately Shared Photo Streams to work, the recipient will not only have to have an Apple ID, but it will have to be an iCloud account:
    Friends and family with iCloud accounts can view your photos in the Photos app on any device using iOS 6 or later; on a Mac in iPhoto 9.4 or Aperture 3.4 or later; on a Windows PC with Windows Vista or later and iCloud Control Panel 2.0 or later installed; or on a second generation or later Apple TV with software version 5.1 or later installed. They can also view your photos on the web if you enable Public Website in the settings or options for your Shared Photo Stream.
    Since you do not have an iCloud account and just and Apple ID, your friend can share the photo stream as a public website so that you can view it, as stated in the same article: 
    Can I share with people who don't have an iCloud account?
    Yes. If you enable Public Website in the settings or options for your shared photo stream your photos will be published to a website that anyone can view in an up-to-date web browser.
    To be able to change an Apple ID to an iCloud account, you would need an iPhone, iPad, or iPod touch with iOS 5 or later or a Mac with OS X Lion v10.7.4 or later as stated in the following article:
    Creating an iCloud account: Frequently Asked Questions
    http://support.apple.com/kb/HT4436
    Best,
    Sheila M.

Maybe you are looking for

  • My itunes will not recognize my ipod shuffle after installing Mcafee

    My itunes will not recognize my Ipod shuffle, I have tried almost everything Itunes has suggested including uninstalling and installing Itunes.  I am at a loss, the computer recognizes the ipod and assigns a drive to it.  When I click on the drive th

  • Dynamic Dropdown key bind in the row

    hi all, i am facing a typical scenario where, <b>for each row in a table of 10 cells i have 1 cell with dropdownbykey control. the requirement is that based on the row's data the dropdownkey's content differs. ie., row 1's -> dropdownkey control's co

  • WRVS4400N does not allow wireless connections

    I've had the WRVS4400N for about six months. Three times in the past two months I have had to factory reset the device and reconfigure it because it would not allow any wireless connections. Perhaps unfortunately I applied the latest firmware update

  • Cloning with rman

    Hi all, cloning the database using rman. i configure everything and finally executed RMAN> duplicate target database to 'clone'; It have executed. but because of some problem with naming convention of directories it is cancelled. I resoleved that and

  • MAC address 00:00:00:00:00:00

    In 802.3 Ethernet protocol....if MAC address is not assigned to a Ethernet controller (i.e. 00:00:00:00:00:00) is it allowed to receive broadcast frames (FF:FF:FF:FF:FF:FF)? I mean ARP Request frames from other nodes in the network. ~ Sandeep