Fix importing an archive containing colons (:) in the names on Windows
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / GzipLeveledStructureProvider.java
CommitLineData
7c62be2f
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
13package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
14
15import java.io.IOException;
16import java.io.InputStream;
17import java.util.ArrayList;
18import java.util.List;
19
20import org.eclipse.tracecompass.internal.tmf.ui.Activator;
21import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
22import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider;
23
24/**
25 * Leveled Structure provider for Gzip file
26 */
27@SuppressWarnings("restriction")
28public class GzipLeveledStructureProvider implements ILeveledImportStructureProvider {
29
30 private final GzipFile fFile;
31 private final GzipEntry root = new GzipEntry();
32 private final GzipEntry fEntry;
33
34 /**
35 * Creates a <code>GzipFileStructureProvider</code>, which will operate on
36 * the passed Gzip file.
37 *
38 * @param sourceFile
39 * the source GzipFile
40 */
41 public GzipLeveledStructureProvider(GzipFile sourceFile) {
42 super();
43
44 fFile = sourceFile;
45 fEntry = sourceFile.entries().nextElement();
46 }
47
48 @Override
49 public List getChildren(Object element) {
50 ArrayList<Object> children = new ArrayList<>();
51 if (element == root) {
52 children.add(fEntry);
53 }
54 return children;
55 }
56
57 @Override
58 public InputStream getContents(Object element) {
59 return fFile.getInputStream((GzipEntry) element);
60 }
61
62 @Override
63 public String getFullPath(Object element) {
c2750d24
MAL
64 String name = ((GzipEntry) element).getName();
65 return ArchiveUtil.toValidNamesPath(name).toOSString();
7c62be2f
MAL
66 }
67
68 @Override
69 public String getLabel(Object element) {
70 if (element != root && element != fEntry) {
71 throw new IllegalArgumentException();
72 }
c2750d24
MAL
73 String name = ((GzipEntry) element).getName();
74 if (element.equals(root)) {
75 return name;
76 }
77
78 return ArchiveUtil.toValidNamesPath(name).lastSegment();
7c62be2f
MAL
79 }
80
81 /**
82 * Returns the entry that this importer uses as the root sentinel.
83 *
84 * @return GzipEntry entry
85 */
86 @Override
87 public GzipEntry getRoot() {
88 return root;
89 }
90
91 @Override
92 public boolean closeArchive() {
93 try {
94 fFile.close();
95 } catch (IOException e) {
96 Activator.getDefault().logError(DataTransferMessages.ZipImport_couldNotClose
97 + fFile.getName(), e);
98 return false;
99 }
100 return true;
101 }
102
103 @Override
104 public boolean isFolder(Object element) {
105 return ((GzipEntry) element).getFileType() == GzipEntry.DIRECTORY;
106 }
107
108 @Override
109 public void setStrip(int level) {
110 // Do nothing
111 }
112
113 @Override
114 public int getStrip() {
115 return 0;
116 }
117}
This page took 0.050162 seconds and 5 git commands to generate.