Commit | Line | Data |
---|---|---|
f17bb886 MAL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Marc-Andre Laperle - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.IOException; | |
17 | import java.net.URI; | |
18 | ||
19 | import org.eclipse.core.runtime.IPath; | |
20 | import org.eclipse.core.runtime.Path; | |
21 | import org.eclipse.core.runtime.URIUtil; | |
22 | ||
23 | /** | |
24 | * The "GZIP" implementation of an IFileSystemObject. For a GZIP file that is | |
25 | * not in a tar. | |
26 | */ | |
27 | class GzipFileSystemObject implements IFileSystemObject { | |
28 | ||
29 | private GzipEntry fFileSystemObject; | |
30 | private String fArchivePath; | |
31 | ||
32 | GzipFileSystemObject(GzipEntry fileSystemObject, String archivePath) { | |
33 | fFileSystemObject = fileSystemObject; | |
34 | fArchivePath = archivePath; | |
35 | } | |
36 | ||
37 | @Override | |
38 | public String getName() { | |
39 | return new Path(fFileSystemObject.getName()).lastSegment(); | |
40 | } | |
41 | ||
42 | @Override | |
43 | public String getAbsolutePath() { | |
44 | throw new UnsupportedOperationException(); | |
45 | } | |
46 | ||
47 | @Override | |
48 | public boolean exists() { | |
49 | return true; | |
50 | } | |
51 | ||
52 | @Override | |
53 | public String getSourceLocation() { | |
54 | File file = new File(fArchivePath); | |
55 | try { | |
56 | file = file.getCanonicalFile(); | |
57 | } catch (IOException e) { | |
58 | // Will still work but might have extra ../ in the path | |
59 | } | |
60 | URI uri = file.toURI(); | |
61 | IPath entryPath = new Path(fFileSystemObject.getName()); | |
62 | ||
63 | URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath); | |
64 | return URIUtil.toUnencodedString(jarURI); | |
65 | } | |
66 | ||
67 | @Override | |
68 | public Object getRawFileSystemObject() { | |
69 | return fFileSystemObject; | |
70 | } | |
71 | } |