Refactor ITmfContext and fix dependencies
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / CreateTestFiles.java
CommitLineData
d18dd09b
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
165c977c 10 * Francois Chouinard - Initial API and implementation
d18dd09b
ASL
11 *******************************************************************************/
12
4918b8f2 13package org.eclipse.linuxtools.tmf.tests.stubs;
d18dd09b
ASL
14
15import java.io.BufferedOutputStream;
16import java.io.DataOutputStream;
165c977c 17import java.io.File;
d18dd09b
ASL
18import java.io.FileNotFoundException;
19import java.io.FileOutputStream;
20import java.io.IOException;
165c977c 21import java.util.Random;
d18dd09b
ASL
22
23/**
24 * <b><u>CreateTestFiles</u></b>
25 * <p>
26 * Create a number of event test files of various lengths.
27 * <p>
28 * Events have the following format:
29 * <ul>
30 * <li> [timestamp] [source] [type] [ref] [field]*
31 * <li> There are NB_SOURCES sources and NB_TYPES types.
32 * <li> The number of fields (0 .. NB_TYPES-1) depends on the event type.
33 * </ul>
34 */
3b38ea61 35@SuppressWarnings("nls")
d18dd09b
ASL
36public class CreateTestFiles {
37
38 // ========================================================================
39 // Constants
40 // ========================================================================
41
50adc88e 42 private static final String DIRECTORY = "testfiles";
85fb0e54
FC
43// private static final String FILE_NAMES[] = { "Test-10", "Test-1K", "Test-10K", "Test-100K" };
44// private static final int FILE_SIZES[] = { 10 , 1000 , 10000 , 100000 };
45 private static final String FILE_NAMES[] = { "Test-10K" };
46 private static final int FILE_SIZES[] = { 10000 };
d18dd09b 47
165c977c
FC
48 private static final int NB_SOURCES = 15;
49 private static final int NB_TYPES = 7;
d18dd09b
ASL
50
51 // ========================================================================
52 // Constructors
53 // ========================================================================
54
55 /**
56 * @param args
57 */
58 public static void main(String[] args) {
165c977c
FC
59
60 try {
50adc88e 61 System.out.println("Creating test files in directory: " + new File(".").getCanonicalPath() + File.separator + DIRECTORY);
165c977c
FC
62 } catch (IOException e) {
63 e.printStackTrace();
64 }
65
d18dd09b
ASL
66 for (int i = 0; i < FILE_SIZES.length; i++) {
67 try {
85fb0e54
FC
68 createTestFile("testfiles" + File.separator + "O-" + FILE_NAMES[i], FILE_SIZES[i], true, true);
69 createTestFile("testfiles" + File.separator + "E-" + FILE_NAMES[i], FILE_SIZES[i], true, false);
70 createTestFile("testfiles" + File.separator + "R-" + FILE_NAMES[i], FILE_SIZES[i], false, false);
6e85c58d
FC
71 } catch (FileNotFoundException e) {
72 } catch (IOException e) {
d18dd09b
ASL
73 }
74 }
165c977c
FC
75
76 System.out.println("Done.");
d18dd09b
ASL
77 }
78
79 // ========================================================================
80 // Operators
81 // ========================================================================
82
83 /**
84 * @param file
85 * @param size
165c977c 86 * @param monotonic
d18dd09b
ASL
87 * @throws FileNotFoundException
88 * @throws IOException
89 */
85fb0e54 90 private static void createTestFile(String file, int size, boolean monotonic, boolean odd) throws FileNotFoundException, IOException {
d18dd09b
ASL
91 DataOutputStream out;
92 System.out.println("Creating " + file);
93 out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
94
165c977c 95 Random generator = new Random(19580427 + size);
85fb0e54 96 long ts = (monotonic && odd) ? -1 : 0;
d18dd09b 97 for (int i = 0; i < size; i++) {
85fb0e54 98 ts += monotonic ? 2 : generator.nextInt(10);
d18dd09b
ASL
99 int sourceIndex = i % NB_SOURCES;
100 int typeIndex = i % NB_TYPES;
165c977c 101 out.writeLong(ts); // Timestamp
d18dd09b
ASL
102 out.writeUTF("Source-" + sourceIndex); // Source
103 out.writeUTF("Type-" + typeIndex); // Type
165c977c 104 out.writeInt(i + 1); // Reference (event #)
d18dd09b
ASL
105 for (int j = 0; j < typeIndex; j++) {
106 out.writeUTF("Field-" + sourceIndex + "-" + j);
107 }
108 }
109 out.flush();
110 out.close();
111 }
165c977c 112
d18dd09b 113}
This page took 0.03662 seconds and 5 git commands to generate.