tmf: Bug 478578: Add weak binary validation to text trace types
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / text / TextTrace.java
index 0fe75752d7a7a6dc5f0432ab98245f8a41457287..1e41e06688bdd2046a61725b852d39a2468db6a4 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
@@ -87,6 +88,14 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
         if (!file.isFile()) {
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Not a file. It's a directory: " + path); //$NON-NLS-1$
         }
+        try {
+            if (!TmfTraceUtils.isText(file)) {
+                return new TraceValidationStatus(0, Activator.PLUGIN_ID);
+            }
+        } catch (IOException e) {
+            Activator.logError("Error validating file: " + path, e); //$NON-NLS-1$
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "IOException validating file: " + path, e); //$NON-NLS-1$
+        }
         int confidence = 0;
         try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
             int lineCount = 0;
This page took 0.025078 seconds and 5 git commands to generate.