MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

compression/GZIPcompress.java:11–44  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

9
10public class GZIPcompress {
11 public static void main(String[] args) {
12 if(args.length == 0) {
13 System.out.println(
14 "Usage: \nGZIPcompress file\n" +
15 "\tUses GZIP compression to compress " +
16 "the file to test.gz");
17 System.exit(1);
18 }
19 try(
20 InputStream in = new BufferedInputStream(
21 new FileInputStream(args[0]));
22 BufferedOutputStream out =
23 new BufferedOutputStream(
24 new GZIPOutputStream(
25 new FileOutputStream("test.gz")))
26 ) {
27 System.out.println("Writing file");
28 int c;
29 while((c = in.read()) != -1)
30 out.write(c);
31 } catch(IOException e) {
32 throw new RuntimeException(e);
33 }
34 System.out.println("Reading file");
35 try(
36 BufferedReader in2 = new BufferedReader(
37 new InputStreamReader(new GZIPInputStream(
38 new FileInputStream("test.gz"))))
39 ) {
40 in2.lines().forEach(System.out::println);
41 } catch(IOException e) {
42 throw new RuntimeException(e);
43 }
44 }
45}

Callers

nothing calls this directly

Calls 1

readMethod · 0.45

Tested by

no test coverage detected