|
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) { |