mirnshi:a_java_class_to_get_a_compressed_file_from_the_server
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | mirnshi:a_java_class_to_get_a_compressed_file_from_the_server [2009/12/19 05:22] (current) – created mirnshi | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 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. | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | try { | ||
+ | // String fname = request.getParameter(" | ||
+ | fname = filename; | ||
+ | File f = new File(fname); | ||
+ | if (f.canRead()) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } catch (Exception e) { | ||
+ | // TODO Auto-generated catch block | ||
+ | // | ||
+ | } | ||
+ | } | ||
+ | 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, | ||
+ | } | ||
+ | gzip.close(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | {{tag>}} | ||
+ | |||
+ | ~~LINKBACK~~ | ||
+ | ~~DISCUSSION~~ | ||
mirnshi/a_java_class_to_get_a_compressed_file_from_the_server.txt · Last modified: 2009/12/19 05:22 by mirnshi