/
Metadata.java
622 lines (540 loc) · 24.2 KB
/
Metadata.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/*******************************************************************************
* Copyright (c) 2011, 2023 Ericsson, Ecole Polytechnique de Montreal and others
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Matthew Khouzam - Initial API and implementation
* Simon Marchi - Initial API and implementation
* Matthew Khouzam - Update for live trace reading support
* Bernd Hufmann - Add method to copy metadata file
*******************************************************************************/
package org.eclipse.tracecompass.ctf.core.trace;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.antlr.runtime.ANTLRReaderStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.BaseTree;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.RewriteCardinalityException;
import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.parser.CTFLexer;
import org.eclipse.tracecompass.ctf.parser.CTFParser;
import org.eclipse.tracecompass.ctf.parser.CTFParser.parse_return;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.CTFAntlrMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.CTFJsonMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.CtfAntlrException;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.IOStructGen;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonClockMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonDataStreamMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonEventRecordMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonFieldClassAliasMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonPreambleMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonTraceMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.trace.TraceDeclarationParser;
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
import org.eclipse.tracecompass.internal.ctf.core.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
/**
* The CTF trace metadata TSDL or JSON file
*
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
public class Metadata {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
private static final Charset ASCII_CHARSET = Charset.forName("ASCII"); //$NON-NLS-1$
private static final String TEXT_ONLY_METADATA_HEADER_PREFIX = "/* CTF"; //$NON-NLS-1$
private static final int PREVALIDATION_SIZE = 8;
private static final int BITS_PER_BYTE = Byte.SIZE;
/**
* Name of the metadata file in the trace directory
*/
private static final String METADATA_FILENAME = "metadata"; //$NON-NLS-1$
/**
* Size of the metadata packet header, in bytes, computed by hand.
*/
private static final int METADATA_PACKET_HEADER_SIZE = 37;
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
/**
* Byte order as detected when reading the TSDL magic number.
*/
private ByteOrder fDetectedByteOrder = null;
/**
* The trace file to which belongs this metadata file.
*/
private final CTFTrace fTrace;
private IOStructGen fTreeParser;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Constructs a Metadata object.
*
* @param trace
* The trace to which belongs this metadata file.
*/
public Metadata(CTFTrace trace) {
fTrace = trace;
}
/**
* For network streaming
*/
public Metadata() {
fTrace = new CTFTrace();
}
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
/**
* Returns the ByteOrder that was detected while parsing the metadata.
*
* @return The byte order.
*/
public ByteOrder getDetectedByteOrder() {
return fDetectedByteOrder;
}
/**
* Gets the parent trace
*
* @return the parent trace
*/
public CTFTrace getTrace() {
return fTrace;
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/**
* Parse the metadata file.
*
* @throws CTFException
* If there was a problem parsing the metadata
*/
public void parseFile() throws CTFException {
/*
* Reader. It will contain a StringReader if we are using packet-based
* metadata and it will contain a FileReader if we have text-based
* metadata.
*/
File metadataFile = new File(getMetadataPath());
ByteOrder byteOrder = CTFTrace.startsWithMagicNumber(metadataFile, Utils.TSDL_MAGIC);
fDetectedByteOrder = byteOrder;
try (FileInputStream fis = new FileInputStream(metadataFile);
FileChannel metadataFileChannel = fis.getChannel();
/* Check if metadata is packet-based, if not it is text based */
Reader metadataTextInput = (byteOrder != null ? readBinaryMetaData(metadataFileChannel) : new FileReader(metadataFile));) {
readMetaDataText(metadataTextInput);
} catch (FileNotFoundException e) {
throw new CTFException("Cannot find metadata file!", e); //$NON-NLS-1$
} catch (IOException | ParseException e) {
throw new CTFException(e);
} catch (RecognitionException e) {
throw new CtfAntlrException(e);
} catch (RewriteCardinalityException e) {
/* needs to be separate to avoid casting as exception */
throw new CtfAntlrException(e);
}
}
/**
* Parse a json metadata file
*
* @throws CTFException
* if there was an issue parsing the metadata
* @since 4.3
*
*/
public void parseJsonFile() throws CTFException {
File metadataFile = new File(getMetadataPath());
try (InputStream is = new FileInputStream(metadataFile)) {
String json = IOUtils.toString(is, "UTF-8"); //$NON-NLS-1$
ICTFMetadataNode tree = parseJsonToTree(json);
fTreeParser = new IOStructGen(tree, NonNullUtils.checkNotNull(fTrace));
fTreeParser.generate();
} catch (FileNotFoundException e) {
throw new CTFException("Cannot find metadata file!", e); //$NON-NLS-1$
} catch (IOException | ParseException e) {
throw new CTFException(e);
}
}
/**
* Parse the json text to a tree with each fragment as a node
*
* @param json
* String of json text that can be parsed
* @return root of a tree containing all the fragments
* @throws CTFException
* @since 4.1
*/
private static ICTFMetadataNode parseJsonToTree(String json) throws CTFException {
String[] jsonBlocks = json.split("\u001e"); //$NON-NLS-1$
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
ICTFMetadataNode root = new CTFJsonMetadataNode(null, CTFParser.tokenNames[CTFParser.ROOT], null);
for (int i = 1; i < jsonBlocks.length; i++) {
ICTFMetadataNode fragment;
try {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], CTFJsonMetadataNode.class));
} catch (JsonSyntaxException e) {
throw new CTFException("Trace cannot be parsed as CTF2"); //$NON-NLS-1$
}
String type = fragment.getType();
if (type.equals(JsonMetadataStrings.FRAGMENT_PREAMBLE)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonPreambleMetadataNode.class));
} else if (type.equals(JsonMetadataStrings.FRAGMENT_TRACE)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonTraceMetadataNode.class));
} else if (type.equals(JsonMetadataStrings.FRAGMENT_CLOCK)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonClockMetadataNode.class));
} else if (type.equals(JsonMetadataStrings.FRAGMENT_EVENT_RECORD)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonEventRecordMetadataNode.class));
} else if (type.equals(JsonMetadataStrings.FRAGMENT_DATA_STREAM)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonDataStreamMetadataNode.class));
} else if (type.equals(JsonMetadataStrings.FRAGMENT_FIELD_ALIAS)) {
fragment = Objects.requireNonNull(gson.fromJson(jsonBlocks[i], JsonFieldClassAliasMetadataNode.class));
}
((CTFJsonMetadataNode) fragment).initialize();
root.addChild(fragment);
fragment.setParent(root);
}
return root;
}
/**
* Checks the version of the CTF trace by reading the first JSON fragment
* if it is a CTF2 fragment it updates the major of the trace
*
* @throws CTFException
* throws exception if file is invalid
*
* @since 4.3
*/
public void checkCTFVersion() throws CTFException {
File metadataFile = new File(getMetadataPath());
if (CTFTrace.startsWithRecordSeparator(metadataFile, Utils.CTF2_START)) {
try (InputStream is = new FileInputStream(metadataFile)) {
String json = IOUtils.toString(is, "UTF-8").split(Utils.RECORD_SEPARATOR)[1]; //$NON-NLS-1$
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
@Nullable ICTFMetadataNode metadata;
metadata = gson.fromJson(json, JsonPreambleMetadataNode.class);
TraceDeclarationParser.INSTANCE.parse(metadata, new TraceDeclarationParser.Param(fTrace, NonNullUtils.checkNotNull(fTrace.getScope())));
} catch (IOException | ParseException e) {
throw new CTFIOException(e);
}
}
}
private Reader readBinaryMetaData(FileChannel metadataFileChannel) throws CTFException {
/* Create StringBuffer to receive metadata text */
StringBuffer metadataText = new StringBuffer();
/*
* Read metadata packet one by one, appending the text to the
* StringBuffer
*/
MetadataPacketHeader packetHeader = readMetadataPacket(
metadataFileChannel, metadataText);
while (packetHeader != null) {
packetHeader = readMetadataPacket(metadataFileChannel,
metadataText);
}
/* Wrap the metadata string with a StringReader */
return new StringReader(metadataText.toString());
}
/**
* Executes a weak validation of the metadata. It checks if a file with name
* metadata exists and if one of the following conditions are met:
* <ul>
* <li>For text-only metadata, the file starts with "/* CTF" (without the
* quotes)</li>
* <li>For packet-based metadata, the file starts with correct magic
* number</li>
* </ul>
*
* @param path
* path to CTF trace directory
* @return <code>true</code> if pre-validation is ok else <code>false</code>
* @throws CTFException
* file channel cannot be created
* @since 1.0
*/
public static boolean preValidate(String path) throws CTFException {
String metadataPath = path + Utils.SEPARATOR + METADATA_FILENAME;
File metadataFile = new File(metadataPath);
if (metadataFile.exists() && metadataFile.length() > PREVALIDATION_SIZE) {
if (CTFTrace.startsWithMagicNumber(metadataFile, Utils.TSDL_MAGIC) != null || CTFTrace.startsWithRecordSeparator(metadataFile, Utils.CTF2_START)) {
return true;
}
try (BufferedReader br = new BufferedReader(new FileReader(metadataFile))) {
String text = br.readLine();
return text.startsWith(TEXT_ONLY_METADATA_HEADER_PREFIX);
} catch (IOException e) {
throw new CTFException(e.getMessage(), e);
}
}
return false;
}
/**
* Read the metadata from a formatted TSDL string
*
* @param data
* the data to read
* @throws CTFException
* this exception wraps a ParseException, IOException or
* CtfAntlrException, three exceptions that can be obtained from
* parsing a TSDL file
*/
public void parseText(String data) throws CTFException {
Reader metadataTextInput = new StringReader(data);
try {
readMetaDataText(metadataTextInput);
} catch (IOException | ParseException e) {
throw new CTFException(e);
} catch (RecognitionException | RewriteCardinalityException e) {
throw new CtfAntlrException(e);
}
}
private void readMetaDataText(Reader metadataTextInput) throws IOException, RecognitionException, ParseException {
ICTFMetadataNode tree = createAST(metadataTextInput);
fTreeParser = new IOStructGen(tree, NonNullUtils.checkNotNull(fTrace));
/* Generate IO structures (declarations) */
fTreeParser.generate();
/* store locally in case of concurrent modification */
ByteOrder detectedByteOrder = getDetectedByteOrder();
if (detectedByteOrder != null && fTrace.getByteOrder() != detectedByteOrder) {
throw new ParseException("Metadata byte order and trace byte order inconsistent."); //$NON-NLS-1$
}
}
/**
* Read a metadata fragment from a formatted TSDL string
*
* @param dataFragment
* the data to read
* @throws CTFException
* this exception wraps a ParseException, IOException or
* CtfAntlrException, three exceptions that can be obtained from
* parsing a TSDL file
*/
public void parseTextFragment(String dataFragment) throws CTFException {
Reader metadataTextInput = new StringReader(dataFragment);
try {
readMetaDataTextFragment(metadataTextInput);
} catch (IOException | ParseException e) {
throw new CTFException(e);
} catch (RecognitionException | RewriteCardinalityException e) {
throw new CtfAntlrException(e);
}
}
private void readMetaDataTextFragment(Reader metadataTextInput) throws IOException, RecognitionException, ParseException {
ICTFMetadataNode tree = createAST(metadataTextInput);
fTreeParser.setTree(tree);
fTreeParser.generateFragment();
}
private static ICTFMetadataNode createAST(Reader metadataTextInput) throws IOException,
RecognitionException {
/* Create an ANTLR reader */
ANTLRReaderStream antlrStream;
antlrStream = new ANTLRReaderStream(metadataTextInput);
/* Parse the metadata text and get the AST */
CTFLexer ctfLexer = new CTFLexer(antlrStream);
CommonTokenStream tokens = new CommonTokenStream(ctfLexer);
CTFParser ctfParser = new CTFParser(tokens, false);
parse_return pr = ctfParser.parse();
ICTFMetadataNode root = new CTFAntlrMetadataNode(null, CTFParser.tokenNames[CTFParser.ROOT], null); // $NON-NLS-1$
CommonTree tree = pr.getTree();
populate(tree, root);
ICTFMetadataNode newRoot = root.getChild(0);
newRoot.setParent(null);
return newRoot;
}
private static void populate(BaseTree tree, ICTFMetadataNode dest) {
ICTFMetadataNode current = new CTFAntlrMetadataNode(dest, CTFParser.tokenNames[tree.getType()], tree.getText());
List<?> children = tree.getChildren();
if (children != null) {
for (Object childObj : children) {
if (childObj instanceof BaseTree) {
populate((BaseTree) childObj, current);
}
}
}
}
private String getMetadataPath() {
/* Path of metadata file = trace directory path + metadata filename */
if (fTrace.getTraceDirectory() == null) {
return ""; //$NON-NLS-1$
}
return fTrace.getTraceDirectory().getPath()
+ Utils.SEPARATOR + METADATA_FILENAME;
}
/**
* Reads a metadata packet from the given metadata FileChannel, do some
* basic validation and append the text to the StringBuffer.
*
* @param metadataFileChannel
* Metadata FileChannel
* @param metadataText
* StringBuffer to which the metadata text will be appended.
* @return A structure describing the header of the metadata packet, or null
* if the end of the file is reached.
* @throws CTFException
*/
private MetadataPacketHeader readMetadataPacket(
FileChannel metadataFileChannel, StringBuffer metadataText)
throws CTFException {
/* Allocate a ByteBuffer for the header */
ByteBuffer headerByteBuffer = ByteBuffer.allocate(METADATA_PACKET_HEADER_SIZE);
/* Read the header */
try {
int nbBytesRead = metadataFileChannel.read(headerByteBuffer);
/* Return null if EOF */
if (nbBytesRead < 0) {
return null;
}
if (nbBytesRead != METADATA_PACKET_HEADER_SIZE) {
throw new CTFException("Error reading the metadata header."); //$NON-NLS-1$
}
} catch (IOException e) {
throw new CTFException("Error reading the metadata header.", e); //$NON-NLS-1$
}
/* Set ByteBuffer's position to 0 */
headerByteBuffer.position(0);
/* Use byte order that was detected with the magic number */
headerByteBuffer.order(fDetectedByteOrder);
MetadataPacketHeader header = new MetadataPacketHeader(headerByteBuffer);
/* Check TSDL magic number */
if (!header.isMagicValid()) {
throw new CTFException("TSDL magic number does not match"); //$NON-NLS-1$
}
/* Check UUID */
if (!fTrace.uuidIsSet()) {
fTrace.setUUID(header.getUuid());
} else if (!fTrace.getUUID().equals(header.getUuid())) {
throw new CTFException("UUID mismatch"); //$NON-NLS-1$
}
/* Extract the text from the packet */
int payloadSize = ((header.getContentSize() / BITS_PER_BYTE) - METADATA_PACKET_HEADER_SIZE);
if (payloadSize < 0) {
throw new CTFException("Invalid metadata packet payload size."); //$NON-NLS-1$
}
int skipSize = (header.getPacketSize() - header.getContentSize()) / BITS_PER_BYTE;
/* Read the payload + the padding in a ByteBuffer */
ByteBuffer payloadByteBuffer = ByteBuffer.allocateDirect(payloadSize
+ skipSize);
try {
metadataFileChannel.read(payloadByteBuffer);
} catch (IOException e) {
throw new CTFException("Error reading metadata packet payload.", e); //$NON-NLS-1$
}
payloadByteBuffer.rewind();
/* Read only the payload from the ByteBuffer into a byte array */
byte payloadByteArray[] = new byte[payloadByteBuffer.remaining()];
payloadByteBuffer.get(payloadByteArray, 0, payloadSize);
/* Convert the byte array to a String */
String str = new String(payloadByteArray, 0, payloadSize, ASCII_CHARSET);
/* Append it to the existing metadata */
metadataText.append(str);
return header;
}
private static class MetadataPacketHeader {
private static final int UUID_SIZE = 16;
private final int fMagic;
private final UUID fUuid;
private final int fChecksum;
private final int fContentSize;
private final int fPacketSize;
private final byte fCompressionScheme;
private final byte fEncryptionScheme;
private final byte fChecksumScheme;
private final byte fCtfMajorVersion;
private final byte fCtfMinorVersion;
public MetadataPacketHeader(ByteBuffer headerByteBuffer) throws CTFException {
/* Read from the ByteBuffer */
fMagic = headerByteBuffer.getInt();
byte[] uuidBytes = new byte[UUID_SIZE];
headerByteBuffer.get(uuidBytes);
fUuid = Utils.makeUUID(uuidBytes);
fChecksum = headerByteBuffer.getInt();
fContentSize = headerByteBuffer.getInt();
fPacketSize = headerByteBuffer.getInt();
fCompressionScheme = headerByteBuffer.get();
fEncryptionScheme = headerByteBuffer.get();
fChecksumScheme = headerByteBuffer.get();
fCtfMajorVersion = headerByteBuffer.get();
fCtfMinorVersion = headerByteBuffer.get();
}
public boolean isMagicValid() {
return fMagic == Utils.TSDL_MAGIC;
}
public UUID getUuid() {
return fUuid;
}
public int getContentSize() {
return fContentSize;
}
public int getPacketSize() {
return fPacketSize;
}
@Override
public String toString() {
/* Only for debugging, shouldn't be externalized */
/* Therefore it cannot be covered by test cases */
return "MetadataPacketHeader [magic=0x" //$NON-NLS-1$
+ Integer.toHexString(fMagic) + ", uuid=" //$NON-NLS-1$
+ fUuid.toString() + ", checksum=" + fChecksum //$NON-NLS-1$
+ ", contentSize=" + fContentSize + ", packetSize=" //$NON-NLS-1$ //$NON-NLS-2$
+ fPacketSize + ", compressionScheme=" + fCompressionScheme //$NON-NLS-1$
+ ", encryptionScheme=" + fEncryptionScheme //$NON-NLS-1$
+ ", checksumScheme=" + fChecksumScheme //$NON-NLS-1$
+ ", ctfMajorVersion=" + fCtfMajorVersion //$NON-NLS-1$
+ ", ctfMinorVersion=" + fCtfMinorVersion + ']'; //$NON-NLS-1$
}
}
/**
* Copies the metadata file to a destination directory.
*
* @param path
* the destination directory
* @return the path to the target file
* @throws IOException
* if an error occurred
*
* @since 1.0
*/
public Path copyTo(final File path) throws IOException {
Path source = FileSystems.getDefault().getPath(fTrace.getTraceDirectory().getAbsolutePath(), METADATA_FILENAME);
Path destPath = FileSystems.getDefault().getPath(path.getAbsolutePath());
return Files.copy(source, destPath.resolve(source.getFileName()));
}
}