User Tools

Site Tools


mirnshi:a_java_class_to_get_a_compressed_file_from_the_server

A java class to get a compressed file from the server

Some guys often ask me to help them to get some files from the server, such as tomcat log. Everytime I must open ftp client to connect the server, download these file. The lazy man need a smart way to do this job. Now they can help themselves.

 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.zip.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 public class ZGet {
     public void get(HttpServletRequest request, HttpServletResponse response, String filename) {
         try {
             // String fname = request.getParameter("xpath");
             fname = filename;
             File f = new File(fname);
             if (f.canRead()) {
                 response.setContentType("application/x-gzip");
                 response.setHeader("Location", f.getName());  
                 response.setHeader("Content-Disposition", "attachment; filename=" + f.getName() + ".gz");
                 get(new FileInputStream(filename), response.getOutputStream());
                 response.getOutputStream().flush();
                 response.getOutputStream().close();
              }
          } catch (Exception e) {
              // TODO Auto-generated catch block
              //e.printStackTrace();
          }  
      }
      private void get(InputStream in, OutputStream out) throws IOException {
          if (in == null || out == null) {
              return;
          }
          byte[] buffer = new byte[1024];
          int i = -1;
          GZIPOutputStream gzip = new GZIPOutputStream(out);
          while ((i = in.read(buffer)) != -1) {
              gzip.write(buffer, 0, i);
          }
          gzip.close();
      }
  }

Discussion

, AXBLMHFZYBu, 2012/01/06 02:37

This is a rellay intelligent way to answer the question.

, 2019/03/27 01:58

http://www.katespade-outlet.us http://www.nikeflipflops.org http://www.nobisjackets.us.com http://www.ubiqshoes.us http://www.baltimoreoriolesjerseys.us http://www.moncler-outlet.us.com http://www.clevelandbrownsjerseys.us http://www.coachoutletcoachs.us.com http://www.hydroflask.us.com http://www.jordans-fusion.com http://www.christianlouboutinshoes.org http://www.coach-factoryoutlets.us.com http://www.ultraboosts.us.com http://www.fitflopsoutletsale.com http://www.canada-gooseoutletstore.name http://www.superdry.me.uk http://www.cheapjordansoutlet.in.net http://www.cheapnba-jerseys.us.com http://www.mbtshoesuk.org.uk http://www.coach-factoryoutletstore.us.com http://www.coachoutlet-canada.ca http://www.ralphlaurenoutlet.in.net http://www.edhardyoutlet.us http://www.jimmychoo.us.com http://www.hermesoutlets.us.com http://www.northfacejacket.us.com http://www.fjallravenoutlet.us.com http://www.louboutinoutlets.us.com http://www.coloradorockiesjerseys.us http://www.kendrascottjewelrys.com http://www.ralphlaurenpolo.us.org http://www.redbottomsshoes.us.com http://www.maujimsunglasses.com http://www.newenglandpatriotsjerseys.us.com http://www.texansjerseys.us http://www.balenciagasneaker.us.com http://www.monclersitoufficiale.it http://www.airhuaracheuk.org.uk http://www.cheapmlbjerseys.net http://www.canadagoosefactory.us http://www.converse-uk.me.uk http://www.christian-louboutins.fr http://www.coachoutlet-online.eu.com http://www.outletcoachoutlets.us.com http://www.truereligionjeans-sale.us.com http://www.lacosteoutlet.us.org http://www.greenbaypackersjersey.us http://www.prada.us.org http://www.pandorajewelrysoutlet.us.com http://www.cheapraybansunglasses.net.co http://www.airjordanpaschere.fr http://www.kate-spadeoutlet.us.com http://www.christian-louboutinoutlet.us.com http://www.rosherun.org http://www.airmax2017.org http://www.ralphlaurenpolo.in.net http://www.coachoutletstores.eu.com http://www.uggbootssale.ca http://www.northfaceoutlet.us.com http://www.edhardyclothing.us.com http://www.chelseajerseys.us http://www.valentinooutletstore.us.com http://www.philadelphiaphilliesjerseys.us http://www.nikeoutletonline.us.com http://www.coachoutlet-clearance.us.com http://www.detroitlionsjerseys.us http://www.converseshoesoutlet.us.com http://www.coachoutletstores.com.co http://www.barcelonajersey.us http://www.supremeclothinguk.co.uk http://www.davidyurmanjewelry.us.com http://www.seattleseahawksjersey.us http://www.nike-outletstore.us.com http://www.airjordan.us.org http://www.michaelkorsoutlet-clearance.us.org http://www.christianlouboutin-outlet.in.net http://www.mcm-outlets.us.com http://www.ferragamoshoes.us http://www.celine-outlet.us.com http://www.converseshoes.us.com http://www.ralphlauren-poloshirt.org.uk http://www.moncleroutlets.us.org http://www.polo-outlets.com.co http://www.coachoutletclearancesale.us.com http://www.coachhandbagsclearance.us.com http://www.snapbackhats.us.com http://www.minnesotavikingsjersey.us http://www.coachoutletclearance.us.com http://www.torontobluejaysjerseys.us http://www.kobeshoes.us.com http://www.airmax97.org http://www.adadassuperstar.com http://www.us-coatsjackets.com http://www.christianlouboutinoff.us http://www.oaklandraidersjerseys.us http://www.nike-shoes.us.org http://www.canadasgooseoutlet.us.com http://www.nikehyperdunks.com QQQ

, http://theprettyguineapig.com/amoxicillin/, 2019/04/19 20:05

http://theprettyguineapig.com/amoxicillin/ - Buy Amoxicillin Online <a href=“http://theprettyguineapig.com/amoxicillin/”>Amoxicillin 500 Mg</a> bux.ltfi.wiki.freecode.com.cn.lxs.js http://theprettyguineapig.com/amoxicillin/

, http://theprettyguineapig.com/amoxicillin/, 2019/04/19 21:22

http://theprettyguineapig.com/amoxicillin/ - Amoxicillin 500mg Capsules <a href=“http://theprettyguineapig.com/amoxicillin/”>Amoxicillin 500mg Capsules</a> bmr.nmml.wiki.freecode.com.cn.ixo.vf http://theprettyguineapig.com/amoxicillin/

Enter your comment. Wiki syntax is allowed:
 
mirnshi/a_java_class_to_get_a_compressed_file_from_the_server.txt · Last modified: 2009/12/19 05:22 by mirnshi