1 24 25 26 30 31 package org.objectweb.clif.analyser; 32 33 import java.util.* ; 34 import java.io.* ; 35 36 37 public class Concat { 39 private BufferedReader[] files ; 40 private int compteur ; 41 private PrintStream pfile ; 42 private String [] tampon ; 43 44 public Concat(Vector filesName, int max, String fileOut) { 45 this.compteur = max ; 47 48 try { 50 FileOutputStream file = new FileOutputStream(fileOut); 51 this.pfile = new PrintStream(file); 52 } 53 catch (Exception e) { 54 e.printStackTrace() ; 55 System.exit(0) ; 56 } 57 58 this.files = new BufferedReader[filesName.size()] ; 60 try { 61 for (int i=0;i<filesName.size();i++) { 62 FileInputStream fileInput = new FileInputStream((String )filesName.elementAt(i)); 63 this.files[i] = new BufferedReader(new InputStreamReader(fileInput)); 64 } 65 } 66 catch (Exception e) { 67 e.printStackTrace() ; 68 System.exit(0) ; 69 } 70 71 this.tampon = new String [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 String [][] lines = new String [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; 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 (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 (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; for(int m = 0; lines[j][m]!=null;m++) 110 { 111 st = new StringTokenizer(lines[j][m],";") ; 112 no = (new Integer (st.nextToken())).intValue() ; 113 if(no<temp) { temp = no; min = m;} 114 } 115 st = new StringTokenizer(lines[j][min],";") ; 116 no = (new Integer (st.nextToken())).intValue() ; 117 } 118 } 119 } 120 cmp++ ; 121 } 122 } 123 catch (Exception e) { 124 e.printStackTrace() ; 125 System.exit(0) ; 126 } 127 } 128 129 public void print(String line) { 130 try { 131 132 this.pfile.println(line) ; 133 } 134 catch (Exception e) { 135 e.printStackTrace() ; 136 System.exit(0) ; 137 } 138 } 139 140 141 142 } 143 | Popular Tags |