File: GzipFileExtractor.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (48 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package tim.prune.function.filesleuth.extract;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.TimeZone;
import java.util.zip.GZIPInputStream;

import tim.prune.function.filesleuth.data.LocationFilter;
import tim.prune.function.filesleuth.data.TrackContents;


/** Responsible for extracting text from gzipped xml files */
public class GzipFileExtractor implements ContentExtractor
{
	// TODO: Are we ignoring the possibility of gzipped text files here?
	private final File _file;

	public GzipFileExtractor(File inFile) {
		_file = inFile;
	}

	@Override
	public TrackContents getContents(TimeZone inTimezone)
	{
		if (_file == null || !_file.isFile() || !_file.canRead()) {
			return new TrackContents(inTimezone);
		}
		try (GZIPInputStream istream = new GZIPInputStream(new FileInputStream(_file)))
		{
			return new XmlFileExtractor(istream).getContents(inTimezone);
		} catch (IOException ignored) {}
		return new TrackContents(inTimezone);
	}

	@Override
	public boolean matchesFilter(LocationFilter inFilter)
	{
		if (_file == null || !_file.isFile() || !_file.canRead()) {
			return false;
		}
		try (GZIPInputStream istream = new GZIPInputStream(new FileInputStream(_file)))
		{
			return new XmlFileExtractor(istream).matchesFilter(inFilter);
		} catch (IOException ignored) {}
		return false;
	}
}