Renamed the bundle class.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / 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:
4c5b8099 10 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
d18dd09b
ASL
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf;
14
15import java.io.BufferedOutputStream;
16import java.io.DataOutputStream;
d18dd09b
ASL
17import java.io.FileNotFoundException;
18import java.io.FileOutputStream;
19import java.io.IOException;
d18dd09b
ASL
20
21/**
22 * <b><u>CreateTestFiles</u></b>
23 * <p>
24 * Create a number of event test files of various lengths.
25 * <p>
26 * Events have the following format:
27 * <ul>
28 * <li> [timestamp] [source] [type] [ref] [field]*
29 * <li> There are NB_SOURCES sources and NB_TYPES types.
30 * <li> The number of fields (0 .. NB_TYPES-1) depends on the event type.
31 * </ul>
32 */
33public class CreateTestFiles {
34
35 // ========================================================================
36 // Constants
37 // ========================================================================
38
4c5b8099
FC
39 private static final String FILE_NAMES[] = { "Test-1K", "Test-10K", "Test-100K", "Test-1M"};
40 private static final int FILE_SIZES[] = { 1000, 10000, 100000, 1000000 };
d18dd09b 41
4c5b8099
FC
42 private static final int NB_SOURCES = 3;
43 private static final int NB_TYPES = 5;
d18dd09b
ASL
44
45 // ========================================================================
46 // Constructors
47 // ========================================================================
48
49 /**
50 * @param args
51 */
52 public static void main(String[] args) {
d18dd09b
ASL
53 for (int i = 0; i < FILE_SIZES.length; i++) {
54 try {
4c5b8099 55 createFile(FILE_NAMES[i], FILE_SIZES[i]);
d18dd09b
ASL
56 } catch (Exception e) {
57 }
58 }
4c5b8099 59 System.out.println("Done.");
d18dd09b
ASL
60 }
61
62 // ========================================================================
63 // Operators
64 // ========================================================================
65
66 /**
67 * @param file
68 * @param size
d18dd09b
ASL
69 * @throws FileNotFoundException
70 * @throws IOException
71 */
4c5b8099 72 private static void createFile(String file, int size) throws FileNotFoundException, IOException {
d18dd09b
ASL
73 DataOutputStream out;
74 System.out.println("Creating " + file);
75 out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
76
d18dd09b 77 for (int i = 0; i < size; i++) {
d18dd09b
ASL
78 int sourceIndex = i % NB_SOURCES;
79 int typeIndex = i % NB_TYPES;
4c5b8099 80 out.writeLong(i); // Timestamp
d18dd09b
ASL
81 out.writeUTF("Source-" + sourceIndex); // Source
82 out.writeUTF("Type-" + typeIndex); // Type
4c5b8099 83 out.writeInt(i); // Reference
d18dd09b
ASL
84 for (int j = 0; j < typeIndex; j++) {
85 out.writeUTF("Field-" + sourceIndex + "-" + j);
86 }
87 }
88 out.flush();
89 out.close();
90 }
d18dd09b 91}
This page took 0.038834 seconds and 5 git commands to generate.