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 1208-1211 Link Here
1208
				ProfileUIManager.getInstance().startMonitoring(agentProxy);			
1211
				ProfileUIManager.getInstance().startMonitoring(agentProxy);			
1209
		}
1212
		}
1210
    }
1213
    }
1214
1215
    public static boolean isTBFFile(InputStream readStream) throws IOException {
1216
        byte[] magic = new byte[4];
1217
1218
        if (readStream.read(magic) > 1) {
1219
            if ((magic[1] == 'T') && (magic[2] == 'B') && (magic[3] == 'F')) {
1220
                return true;
1221
            }
1222
        }
1223
1224
        return false;
1225
    }
1226
1227
    public static boolean isTBFFile(String fileName) throws IOException {
1228
        FileInputStream readStream = new FileInputStream(fileName);
1229
        boolean ret = isTBFFile(readStream);
1230
1231
        readStream.close();
1232
        readStream = null;
1233
1234
        return ret;
1235
    }
1236
1237
    public static boolean isXMLFile(InputStream readStream) throws IOException {
1238
        byte[] magic = new byte[5];
1239
1240
        if (readStream.read(magic) > 1) {
1241
            if ((magic[0] == '<') && 
1242
                (magic[1] == '?') &&
1243
                (magic[2] == 'x') &&
1244
                (magic[3] == 'm') &&
1245
                (magic[4] == 'l')) {
1246
                return true;
1247
            }
1248
        }
1249
1250
        return false;
1251
    }
1252
1253
    public static boolean isXMLFile(String fileName) throws IOException {
1254
        FileInputStream readStream = new FileInputStream(fileName);
1255
        boolean ret = isXMLFile(readStream);
1256
1257
        readStream.close();
1258
        readStream = null;
1259
1260
        return ret;
1261
    }
1211
}
1262
}
(-)src/org/eclipse/hyades/trace/ui/internal/wizard/ImportTracePage1.java (-30 / +47 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 = null;
373
		if(binary) {
374
			processor = new BinaryLoader(fMonitor);
375
			((BinaryLoader)processor).setLoadXml(false);
376
		} else {
377
			processor = new XMLLoader(fMonitor);
378
		}
364
		if (filterUI.getSelectedFilter() != null) {
379
		if (filterUI.getSelectedFilter() != null) {
365
			processor.getContext().setImportFilter(filterUI.getSelectedFilter());
380
			processor.getContext().setImportFilter(filterUI.getSelectedFilter());
366
			processor.getContext().getFilterEngine().init();
381
			processor.getContext().getFilterEngine().init();
Lines 495-501 Link Here
495
		FileDialog dlg = new FileDialog(sourceNameField.getShell());
510
		FileDialog dlg = new FileDialog(sourceNameField.getShell());
496
511
497
		dlg.setFilterPath(currentSource);
512
		dlg.setFilterPath(currentSource);
498
		dlg.setFilterExtensions(new String[] { "*.trcxml", "*.*" });
513
		dlg.setFilterExtensions(new String[] { "*.trcxml", "*.trcbin", "*.*" });
499
		dlg.open();
514
		dlg.open();
500
515
501
		String fileName = dlg.getFileName();
516
		String fileName = dlg.getFileName();
Lines 584-616 Link Here
584
		}
599
		}
585
	}
600
	}
586
601
587
	private void importFile(IProgressMonitor mon, final XMLLoader processor, final File log, InputStream readStream, final String entryName) throws OutOfMemoryError {
602
	private void importFile(IProgressMonitor mon, final XMLLoader processor, final File log, InputStream readStream, final String entryName, final boolean binary) throws OutOfMemoryError {
588
		try {
603
		try {
589
			if (!CommunicationDebug.INSTANCE.debugUseEventMode) {
604
			if (!CommunicationDebug.INSTANCE.debugUseEventMode) {
590
605
591
				final MyBufferedInputStream inputStream = new MyBufferedInputStream(readStream,16*1024);
606
				final MyBufferedInputStream inputStream = new MyBufferedInputStream(readStream,16*1024);
592
				inputStream.mark(1000);
607
					if (!binary) {
593
				byte[] rootElement = new byte[1000];
608
					inputStream.mark(1000);
594
				rootElementRequired=false;
609
					byte[] rootElement = new byte[1000];
595
				try {
610
					rootElementRequired=false;
596
					int readBytes = inputStream.read(rootElement);
611
					try {
597
					String root = new String(rootElement,0,readBytes);
612
						int readBytes = inputStream.read(rootElement);
598
					root = root.toUpperCase();
613
						String root = new String(rootElement,0,readBytes);
599
					if(root.indexOf("<TRACE>") !=-1 || root.indexOf("<COMMONBASEEVENTS ") !=-1 || root.indexOf("<COMMONBASEEVENTS>") !=-1)
614
						root = root.toUpperCase();
600
					{
615
						if(root.indexOf("<TRACE>") !=-1 || root.indexOf("<COMMONBASEEVENTS ") !=-1 || root.indexOf("<COMMONBASEEVENTS>") !=-1)
601
						rootElementRequired=false;
616
						{
602
					}
617
							rootElementRequired=false;
603
					else
618
						}
604
					{
619
						else
605
						rootElementRequired=true;
620
						{
621
							rootElementRequired=true;
622
						}
623
						inputStream.reset();
624
					} catch (IOException e1) {
625
						e1.printStackTrace();
606
					}
626
					}
607
					inputStream.reset();
627
	
608
				} catch (IOException e1) {
628
					if(rootElementRequired)
609
					e1.printStackTrace();
629
						inputStream.addRootTRACEElement();
610
				}
630
				}
611
612
				if(rootElementRequired)
613
					inputStream.addRootTRACEElement();
614
				final String jobName = MessageFormat.format(TraceWizardMessages.IMPORT_FILE, new String[] { "" + log.length(), log.getAbsolutePath() });
631
				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;
632
				final long entryLength = logLength == Long.MAX_VALUE ? log.length() * 10 : logLength;
616
				Job job = new Job(jobName) {
633
				Job job = new Job(jobName) {

Return to bug 209343