tmf: Use Apache Common Compress for importing from archive
[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.apache.commons.compress.archivers.tar.TarArchiveEntry;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.core.runtime.URIUtil;
23
24 /**
25 * The "Tar" implementation of an IFileSystemObject, entries can also be Gzipped
26 * and are uncompressed transparently.
27 */
28 class TarFileSystemObject implements IFileSystemObject {
29
30 private TarArchiveEntry fFileSystemObject;
31 private String fArchivePath;
32
33 TarFileSystemObject(TarArchiveEntry fileSystemObject, String archivePath) {
34 fFileSystemObject = fileSystemObject;
35 fArchivePath = archivePath;
36 }
37
38 @Override
39 public String getName() {
40 return new Path(fFileSystemObject.getName()).lastSegment();
41 }
42
43 @Override
44 public String getAbsolutePath() {
45 throw new UnsupportedOperationException();
46 }
47
48 @Override
49 public boolean exists() {
50 return true;
51 }
52
53 @Override
54 public String getSourceLocation() {
55 File file = new File(fArchivePath);
56 try {
57 file = file.getCanonicalFile();
58 } catch (IOException e) {
59 // Will still work but might have extra ../ in the path
60 }
61 URI uri = file.toURI();
62 IPath entryPath = new Path(fFileSystemObject.getName());
63
64 URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
65 return URIUtil.toUnencodedString(jarURI);
66 }
67
68 @Override
69 public Object getRawFileSystemObject() {
70 return fFileSystemObject;
71 }
72
73 @Override
74 public boolean isDirectory() {
75 return fFileSystemObject.isDirectory();
76 }
77 }
This page took 0.032267 seconds and 5 git commands to generate.