tmf: Make order of files processing more natural during import
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / TarFileSystemObject.java
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 import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
23
24 /**
25 * The "Tar" implementation of an IFileSystemObject, entries can also be Gzipped
26 * and are uncompressed transparently.
27 */
28 @SuppressWarnings("restriction")
29 class TarFileSystemObject implements IFileSystemObject {
30
31 private TarEntry fFileSystemObject;
32 private String fArchivePath;
33
34 TarFileSystemObject(TarEntry fileSystemObject, String archivePath) {
35 fFileSystemObject = fileSystemObject;
36 fArchivePath = archivePath;
37 }
38
39 @Override
40 public String getName() {
41 return new Path(fFileSystemObject.getName()).lastSegment();
42 }
43
44 @Override
45 public String getAbsolutePath() {
46 throw new UnsupportedOperationException();
47 }
48
49 @Override
50 public boolean exists() {
51 return true;
52 }
53
54 @Override
55 public String getSourceLocation() {
56 File file = new File(fArchivePath);
57 try {
58 file = file.getCanonicalFile();
59 } catch (IOException e) {
60 // Will still work but might have extra ../ in the path
61 }
62 URI uri = file.toURI();
63 IPath entryPath = new Path(fFileSystemObject.getName());
64
65 URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
66 return URIUtil.toUnencodedString(jarURI);
67 }
68
69 @Override
70 public Object getRawFileSystemObject() {
71 return fFileSystemObject;
72 }
73
74 @Override
75 public boolean isDirectory() {
76 return fFileSystemObject.getFileType() == TarEntry.DIRECTORY;
77 }
78 }
This page took 0.034937 seconds and 5 git commands to generate.