1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.archiver.util;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23
24 import org.codehaus.plexus.archiver.ArchiverException;
25 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public abstract class Compressor {
30 private final Logger logger = LoggerFactory.getLogger(getClass());
31
32 protected Logger getLogger() {
33 return logger;
34 }
35
36 private File destFile;
37
38 private PlexusIoResource source;
39
40
41
42
43
44
45 public void setDestFile(File compressFile) {
46 this.destFile = compressFile;
47 }
48
49 public File getDestFile() {
50 return destFile;
51 }
52
53
54
55
56 public void setSource(PlexusIoResource source) {
57 this.source = source;
58 }
59
60
61
62
63 public PlexusIoResource getSource() {
64 return source;
65 }
66
67
68
69
70
71
72
73
74
75 private void compressFile(InputStream in, OutputStream zOut) throws IOException {
76 byte[] buffer = new byte[8 * 1024];
77 int count = 0;
78 do {
79 zOut.write(buffer, 0, count);
80 count = in.read(buffer, 0, buffer.length);
81 } while (count != -1);
82 }
83
84
85
86
87 protected void compress(PlexusIoResource resource, OutputStream zOut) throws IOException {
88 try (InputStream in = Streams.bufferedInputStream(resource.getContents())) {
89 compressFile(in, zOut);
90 }
91 }
92
93
94
95
96
97
98 public abstract void compress() throws ArchiverException;
99
100
101
102
103
104
105 public abstract void close() throws ArchiverException;
106 }