Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 209343 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/hyades/trace/ui/internal/util/PDCoreUtil.java (+51 lines)
Lines 11-16 Link Here
11
 **********************************************************************/
11
 **********************************************************************/
12
package org.eclipse.hyades.trace.ui.internal.util;
12
package org.eclipse.hyades.trace.ui.internal.util;
13
13
14
import java.io.FileInputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
14
import java.net.UnknownHostException;
17
import java.net.UnknownHostException;
15
import java.util.ArrayList;
18
import java.util.ArrayList;
16
import java.util.Date;
19
import java.util.Date;
Lines 1202-1205 Link Here
1202
				ProfileUIManager.getInstance().startMonitoring(agentProxy);			
1205
				ProfileUIManager.getInstance().startMonitoring(agentProxy);			
1203
		}
1206
		}
1204
    }
1207
    }
1208
1209
    public static boolean isTBFFile(InputStream readStream) throws IOException {
1210
        byte[] magic = new byte[4];
1211
1212
        if (readStream.read(magic) > 1) {
1213
            if ((magic[1] == 'T') && (magic[2] == 'B') && (magic[3] == 'F')) {
1214
                return true;
1215
            }
1216
        }
1217
1218
        return false;
1219
    }
1220
1221
    public static boolean isTBFFile(String fileName) throws IOException {
1222
        FileInputStream readStream = new FileInputStream(fileName);
1223
        boolean ret = isTBFFile(readStream);
1224
1225
        readStream.close();
1226
        readStream = null;
1227
1228
        return ret;
1229
    }
1230
1231
    public static boolean isXMLFile(InputStream readStream) throws IOException {
1232
        byte[] magic = new byte[5];
1233
1234
        if (readStream.read(magic) > 1) {
1235
            if ((magic[0] == '<') && 
1236
                (magic[1] == '?') &&
1237
                (magic[2] == 'x') &&
1238
                (magic[2] == 'm') &&
1239
                (magic[2] == 'l')) {
1240
                return true;
1241
            }
1242
        }
1243
1244
        return false;
1245
    }
1246
1247
    public static boolean isXMLFile(String fileName) throws IOException {
1248
        FileInputStream readStream = new FileInputStream(fileName);
1249
        boolean ret = isXMLFile(readStream);
1250
1251
        readStream.close();
1252
        readStream = null;
1253
1254
        return ret;
1255
    }
1205
}
1256
}
(-)src/org/eclipse/hyades/trace/ui/internal/wizard/ImportTracePage1.java (-30 / +41 lines)
Lines 35-40 Link Here
35
import org.eclipse.core.runtime.Status;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.core.runtime.jobs.Job;
36
import org.eclipse.core.runtime.jobs.Job;
37
import org.eclipse.hyades.execution.local.CommunicationDebug;
37
import org.eclipse.hyades.execution.local.CommunicationDebug;
38
import org.eclipse.hyades.loaders.util.BinaryLoader;
38
import org.eclipse.hyades.loaders.util.InvalidXMLException;
39
import org.eclipse.hyades.loaders.util.InvalidXMLException;
39
import org.eclipse.hyades.loaders.util.XMLLoader;
40
import org.eclipse.hyades.loaders.util.XMLLoader;
40
import org.eclipse.hyades.models.hierarchy.TRCCollectionMode;
41
import org.eclipse.hyades.models.hierarchy.TRCCollectionMode;
Lines 327-339 Link Here
327
		try {
328
		try {
328
			File log = new File(fInputLog);
329
			File log = new File(fInputLog);
329
330
330
			if (!PDCoreUtil.isZipFile(fInputLog)) {
331
			if (PDCoreUtil.isTBFFile(fInputLog)) { // TBF (binary)
331
				InputStream readStream = new BufferedInputStream(new FileInputStream(log));
332
				InputStream readStream = new BufferedInputStream(new FileInputStream(log));
332
				logLength = log.length();
333
				logLength = log.length();
333
				XMLLoader processor = getNewProcessor();
334
				XMLLoader processor = getNewProcessor(true);
334
				processor.setCollectionMode(collectionMode);
335
				processor.setCollectionMode(collectionMode);
335
				importFile(mon, processor, log, readStream, log.getAbsolutePath());
336
				importFile(mon, processor, log, readStream, log.getAbsolutePath(), true);
336
			} else {
337
			} else if (PDCoreUtil.isZipFile(fInputLog)) { // Zipped XML
337
				ZipFile zf = new ZipFile(log);
338
				ZipFile zf = new ZipFile(log);
338
339
339
				Enumeration entries = zf.entries();
340
				Enumeration entries = zf.entries();
Lines 344-355 Link Here
344
					if (logLength < log.length())
345
					if (logLength < log.length())
345
						logLength = Long.MAX_VALUE;
346
						logLength = Long.MAX_VALUE;
346
347
347
					XMLLoader processor = getNewProcessor();
348
					XMLLoader processor = getNewProcessor(false);
348
					processor.setCollectionMode(collectionMode);
349
					processor.setCollectionMode(collectionMode);
349
					importFile(mon, processor, log, zf.getInputStream(zipEntry), zipEntry.getName());
350
					importFile(mon, processor, log, zf.getInputStream(zipEntry), zipEntry.getName(), false);
350
					if (CommunicationDebug.INSTANCE.debugUseEventMode)
351
					if (CommunicationDebug.INSTANCE.debugUseEventMode)
351
						processor.cleanUp();
352
						processor.cleanUp();
352
				}
353
				}
354
			} else if (PDCoreUtil.isXMLFile(fInputLog)) { // XML
355
				InputStream readStream = new BufferedInputStream(new FileInputStream(log));
356
				logLength = log.length();
357
				XMLLoader processor = getNewProcessor(false);
358
				processor.setCollectionMode(collectionMode);
359
				importFile(mon, processor, log, readStream, log.getAbsolutePath(), false);
360
			} else {
361
				throw new IOException("Invalid trace file format. Supported formats are XML and TBF (binary)");
353
			}
362
			}
354
		} catch (IOException e) {
363
		} catch (IOException e) {
355
			fError = NLS.bind(TraceMessages.IMP_IOEXC, e.getMessage());
364
			fError = NLS.bind(TraceMessages.IMP_IOEXC, e.getMessage());
Lines 359-366 Link Here
359
	/**
368
	/**
360
	 * @return
369
	 * @return
361
	 */
370
	 */
362
	private XMLLoader getNewProcessor() {
371
	private XMLLoader getNewProcessor(boolean binary) {
363
		XMLLoader processor = new XMLLoader(fMonitor);
372
		XMLLoader processor = binary ? new BinaryLoader(fMonitor) : new XMLLoader(fMonitor);
364
		if (filterUI.getSelectedFilter() != null) {
373
		if (filterUI.getSelectedFilter() != null) {
365
			processor.getContext().setImportFilter(filterUI.getSelectedFilter());
374
			processor.getContext().setImportFilter(filterUI.getSelectedFilter());
366
			processor.getContext().getFilterEngine().init();
375
			processor.getContext().getFilterEngine().init();
Lines 495-501 Link Here
495
		FileDialog dlg = new FileDialog(sourceNameField.getShell());
504
		FileDialog dlg = new FileDialog(sourceNameField.getShell());
496
505
497
		dlg.setFilterPath(currentSource);
506
		dlg.setFilterPath(currentSource);
498
		dlg.setFilterExtensions(new String[] { "*.trcxml", "*.*" });
507
		dlg.setFilterExtensions(new String[] { "*.trcbin", "*.trcxml", "*.*" });
499
		dlg.open();
508
		dlg.open();
500
509
501
		String fileName = dlg.getFileName();
510
		String fileName = dlg.getFileName();
Lines 584-616 Link Here
584
		}
593
		}
585
	}
594
	}
586
595
587
	private void importFile(IProgressMonitor mon, final XMLLoader processor, final File log, InputStream readStream, final String entryName) throws OutOfMemoryError {
596
	private void importFile(IProgressMonitor mon, final XMLLoader processor, final File log, InputStream readStream, final String entryName, final boolean binary) throws OutOfMemoryError {
588
		try {
597
		try {
589
			if (!CommunicationDebug.INSTANCE.debugUseEventMode) {
598
			if (!CommunicationDebug.INSTANCE.debugUseEventMode) {
590
599
591
				final MyBufferedInputStream inputStream = new MyBufferedInputStream(readStream,16*1024);
600
				final MyBufferedInputStream inputStream = new MyBufferedInputStream(readStream,16*1024);
592
				inputStream.mark(1000);
601
					if (!binary) {
593
				byte[] rootElement = new byte[1000];
602
					inputStream.mark(1000);
594
				rootElementRequired=false;
603
					byte[] rootElement = new byte[1000];
595
				try {
604
					rootElementRequired=false;
596
					int readBytes = inputStream.read(rootElement);
605
					try {
597
					String root = new String(rootElement,0,readBytes);
606
						int readBytes = inputStream.read(rootElement);
598
					root = root.toUpperCase();
607
						String root = new String(rootElement,0,readBytes);
599
					if(root.indexOf("<TRACE>") !=-1 || root.indexOf("<COMMONBASEEVENTS ") !=-1 || root.indexOf("<COMMONBASEEVENTS>") !=-1)
608
						root = root.toUpperCase();
600
					{
609
						if(root.indexOf("<TRACE>") !=-1 || root.indexOf("<COMMONBASEEVENTS ") !=-1 || root.indexOf("<COMMONBASEEVENTS>") !=-1)
601
						rootElementRequired=false;
610
						{
602
					}
611
							rootElementRequired=false;
603
					else
612
						}
604
					{
613
						else
605
						rootElementRequired=true;
614
						{
615
							rootElementRequired=true;
616
						}
617
						inputStream.reset();
618
					} catch (IOException e1) {
619
						e1.printStackTrace();
606
					}
620
					}
607
					inputStream.reset();
621
	
608
				} catch (IOException e1) {
622
					if(rootElementRequired)
609
					e1.printStackTrace();
623
						inputStream.addRootTRACEElement();
610
				}
624
				}
611
612
				if(rootElementRequired)
613
					inputStream.addRootTRACEElement();
614
				final String jobName = MessageFormat.format(TraceWizardMessages.IMPORT_FILE, new String[] { "" + log.length(), log.getAbsolutePath() });
625
				final String jobName = MessageFormat.format(TraceWizardMessages.IMPORT_FILE, new String[] { "" + log.length(), log.getAbsolutePath() });
615
				final long entryLength = logLength == Long.MAX_VALUE ? log.length() * 10 : logLength;
626
				final long entryLength = logLength == Long.MAX_VALUE ? log.length() * 10 : logLength;
616
				Job job = new Job(jobName) {
627
				Job job = new Job(jobName) {

Return to bug 209343