KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > analyser > Concat


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 */

24
25
26 /**
27  *
28  * @author Damien Croizer
29  */

30
31 package org.objectweb.clif.analyser;
32
33 import java.util.* ;
34 import java.io.* ;
35
36
37 //this class is used to generate the archive.clif file from the collect of all data after each test
38
public class Concat {
39     private BufferedReader[] files ;
40     private int compteur ;
41     private PrintStream pfile ;
42     private String JavaDoc[] tampon ;
43
44     public Concat(Vector filesName, int max, String JavaDoc fileOut) {
45     // init du compteur avec le nb max
46
this.compteur = max ;
47
48     // chargement du flux de sortie
49
try {
50         FileOutputStream file = new FileOutputStream(fileOut);
51         this.pfile = new PrintStream(file);
52     }
53     catch (Exception JavaDoc e) {
54         e.printStackTrace() ;
55         System.exit(0) ;
56     }
57     
58     // chargement des flux d'entrées
59
this.files = new BufferedReader[filesName.size()] ;
60     try {
61         for (int i=0;i<filesName.size();i++) {
62         FileInputStream fileInput = new FileInputStream((String JavaDoc)filesName.elementAt(i));
63         this.files[i] = new BufferedReader(new InputStreamReader(fileInput));
64         }
65     }
66     catch (Exception JavaDoc e) {
67         e.printStackTrace() ;
68         System.exit(0) ;
69     }
70     
71     // init du tab stockant les lignes precedement lues
72
this.tampon = new String JavaDoc[filesName.size()] ;
73     for (int i=0;i<filesName.size();i++)
74         this.tampon[i] = null ;
75     }
76
77     public void concatAllFiles() {
78     int max = this.compteur ;
79     int cmp = 0 ;
80     //we use a buffer of 100 lines in the case of the data were not registred in a stric chronological order
81
String JavaDoc[][] lines = new String JavaDoc[10][101];
82
83             
84     try {
85         for (int i=0;i<this.files.length;i++){ for(int k = 0; k<100;k++) {
86         lines[i][k] = ((BufferedReader)files[i]).readLine();}
87         lines[i][100] = null;
88         }
89         for (int i=0;i<max;i++) {
90         for (int j=0;j<this.files.length;j++) {
91             if(files[j]==null) continue;
92             long temp = 100000000; // this is the maximum date (here a tes of 100000 second is allowed)
93
int min = 0;
94             for(int k = 0; lines[j][k]!=null;k++)
95             {
96                 StringTokenizer st = new StringTokenizer(lines[j][k],";") ;
97                 int no = (new Integer JavaDoc(st.nextToken())).intValue() ;
98                 if(no<temp) { temp = no; min = k;}
99             }
100             StringTokenizer st = new StringTokenizer(lines[j][min],";") ;
101             int no = (new Integer JavaDoc(st.nextToken())).intValue() ;
102             while (no == cmp) {
103             this.print(lines[j][min]);
104             for(int l = min; l < 99 ;l++) lines[j][l] = lines[j][l+1];
105             if(lines[j][0]== null) { files[j] = null; no = 0;}
106             else{
107             lines[j][99] = ((BufferedReader)files[j]).readLine();
108                 temp = 100000000;// this is the maximum date (here a tes of 100000 second is allowed)
109
for(int m = 0; lines[j][m]!=null;m++)
110                 {
111                     st = new StringTokenizer(lines[j][m],";") ;
112                     no = (new Integer JavaDoc(st.nextToken())).intValue() ;
113                     if(no<temp) { temp = no; min = m;}
114                 }
115                 st = new StringTokenizer(lines[j][min],";") ;
116                 no = (new Integer JavaDoc(st.nextToken())).intValue() ;
117             }
118             }
119         }
120         cmp++ ;
121         }
122     }
123     catch (Exception JavaDoc e) {
124         e.printStackTrace() ;
125         System.exit(0) ;
126     }
127     }
128
129     public void print(String JavaDoc line) {
130     try {
131         
132         this.pfile.println(line) ;
133     }
134     catch (Exception JavaDoc e) {
135         e.printStackTrace() ;
136         System.exit(0) ;
137     }
138     }
139
140   
141
142 }
143
Popular Tags