Thread: Client Won't Unzip My Cache!?!?!

Results 1 to 2 of 2
  1. #1 Client Won't Unzip My Cache!?!?! 
    Registered Member

    Join Date
    Jun 2008
    Posts
    1,957
    Thanks given
    7
    Thanks received
    256
    Rep Power
    445
    ok i followed the tut by java'. its like a year old but i got it done. i got it to download but it won't unzip it sadly... its prob something i did.

    here is the code. that is used.


    To Unzip:
    Code:
    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.zip.Adler32;
    import java.util.zip.CheckedInputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    import java.io.*;
    
    public class FileDownload {
    
       public static void unZip(String file) {
          try {
       	final int BUFFER = 2048;
             BufferedOutputStream dest = null;
             FileInputStream fis = new 
    	   FileInputStream(file);
             ZipInputStream zis = new 
    	   ZipInputStream(new BufferedInputStream(fis));
             ZipEntry entry;
             while((entry = zis.getNextEntry()) != null) {
                System.out.println("Extracting: " +entry);
                int count;
                byte data[] = new byte[BUFFER];
                FileOutputStream fos = new 
    			FileOutputStream("C:/ScapeF_file_store_32/" + entry.getName());
                dest = new 
                  BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) 
                  != -1) {
                   dest.write(data, 0, count);
                }
                dest.flush();
                dest.close();
             }
             zis.close();
          } catch(Exception e) {
             e.printStackTrace();
          }
       }
    }
    Code that downloads:

    Code:
    method13(0, (byte)4, "Valadating Cache..");
    	  try {
    	createCacheDir();
    	  } catch(InterruptedException e) {
    	}
    	 if (!new File("C:/ScapeF_file_store_32/cache.zip").exists() || new File("C:/ScapeF_file_store_32/cache.zip").length() < 17693603) {
    	download2("http://www.hotlinkfiles.com/files/2735694_zqihe/cache.zip", "cache.zip");
    	}
    	method13(20, (byte)4, "Buffering Cache..");
              FileDownload.unZip("C:/ScapeF_filestore_32/cache.zip");
            method13(20, (byte)4, "Starting up")
    And..

    Code:
    public void download2(String address, String localFileName) {
    		OutputStream out = null;
    		URLConnection conn = null;
    		InputStream  in = null;
    		try {
    			URL url = new URL(address);
    			out = new BufferedOutputStream(
    			new FileOutputStream(localFileName));
    			conn = url.openConnection();
    			in = conn.getInputStream();
    			byte[] buffer = new byte[1024];
    			int numRead;
    			long numWritten = 0;
    			while ((numRead = in.read(buffer)) != -1) {
    		double percent = numWritten / 17693603.0 * 100.0;
    		NumberFormat nf =  NumberFormat.getNumberInstance();
    		nf.setMaximumFractionDigits(1);
    		String ans = nf.format(percent);
    		int bar = (int)percent;
    			method13(bar, (byte)4, "Downloading Cache - "+ans+"%");
    			out.write(buffer, 0, numRead);
    			numWritten += numRead;
    			}
    		} catch (Exception exception) {
    			exception.printStackTrace();
    		} finally {
    			try {
    				if (in != null) {
    					in.close();
    				}
    				if (out != null) {
    					out.close();
    				}
    			} catch (IOException ioe) {
    			}
    		}
    	}
    it creates the dirrectory and it downloads the cache but as it is.... downloads as cache.zip.

    so it goes C:/ScapeF_file_store_32/cache.zip and then after its done it just goes connecting to get title...retrying in 5....10 blah.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Rupps's Avatar
    Join Date
    Oct 2008
    Age
    28
    Posts
    905
    Thanks given
    317
    Thanks received
    24
    Rep Power
    194
    I did his tut and It worked fine for me, Although it wouldn't let me have any folders in my cache, so all of my images had to be in the same folder as the cache.

    But, I found your problem. In the "Code that Downloads" Change

    FileDownload.unZip("C:/ScapeF_filestore_32/cache.zip");
    to


    FileDownload.unZip("C:/ScapeF_file_store_32/cache.zip");
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •