1
|
package io;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.InputStream;
|
5
|
import java.util.NoSuchElementException;
|
6
|
import java.util.zip.ZipInputStream;
|
7
|
|
8
|
/**
|
9
|
* For ZIP - the first four bytes should be one of the following
|
10
|
* combinations: 50 4B 03 04
|
11
|
* 50 4B 05 06 (empty archive)
|
12
|
* 50 4B 07 08 (spanned archive)
|
13
|
* Source: https://en.wikipedia.org/wiki/List_of_file_signatures
|
14
|
*/
|
15
|
public class ZipInStream implements IZipReader {
|
16
|
|
17
|
private ZipInputStream zipIS;
|
18
|
|
19
|
public ZipInStream(InputStream in) throws IOException {
|
20
|
zipIS = new ZipInputStream(in);
|
21
|
|
22
|
if (zipIS.getNextEntry() == null) {
|
23
|
zipIS.close();
|
24
|
throw new NoSuchElementException();
|
25
|
}
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public int read() throws IOException {
|
30
|
return zipIS.read();
|
31
|
}
|
32
|
|
33
|
@Override
|
34
|
public void close() throws IOException {
|
35
|
zipIS.close();
|
36
|
}
|
37
|
|
38
|
}
|