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
|
DataInputStream dis = new DataInputStream(new FileInputStream(cheminZoneEssai +
"m.ch1"));
// Informations de bufferisation du nom
byte[] nom_buffer = new byte[39];
int nom_restant = nom_buffer.length;
int nom_pos = 0;
// Informations du parcours du fichier
byte[] buffer = new byte[100000];
int bytes = 0;
int flag = 1;
// Remplit le tableau de bit
bytes = dis.read(buffer, 0, buffer.length);
while ( bytes!=-1 ) {
<div style="margin-left:40px">switch ( flag ) {
<div style="margin-left:40px">// Première ligne
case 1:
<div style="margin-left:40px">// Recherche du caractère incriminé
int pos = 0;
while ( pos < bytes && flag==1 )
<div style="margin-left:40px">flag = ( buffer[ pos++ ] == 0x0A ) ? 2 : 1;</div>if ( flag == 1 ) {
<div style="margin-left:40px">// Toujours la première ligne, on continue la lecture
bytes = dis.read(buffer, 0, buffer.length);</div>} else {
<div style="margin-left:40px">// Le caractère a été trouvé, on décale les bytes
bytes -= pos;
for( int i = 0; i < bytes; i ++ )
<div style="margin-left:40px">buffer[ i ] = buffer[ i + pos ];
</div></div>}
// Fin traitement de la première ligne
break;
</div>// Traitement nom
case 2:
<div style="margin-left:40px">if ( bytes >= nom_restant ) {
<div style="margin-left:40px">// le buffer contient assez de caractères
bytes -= nom_restant;
// bufferisation
for(int i = nom_pos, j = 0; i < nom_pos + nom_restant; j++, i++ )
<div style="margin-left:40px">nom_buffer[ i ] = buffer[ j ];</div>flag = 3;
// nettoyage du buffer
for( int i = 0; i < bytes; i++ )
<div style="margin-left:40px">buffer[i] = buffer[i+pos];</div></div>} else {
<div style="margin-left:40px">// Le buffer ne contient pas assez de caractères
for(int i = nom_pos, j = 0; j < bytes; i++; j++)
<div style="margin-left:40px">nom_buffer[ i ] = buffer[ j ];</div>// On avance dans le fichier
bytes = dis.read( buffer, 0, buffer.length );
</div>}
// Fin traitement du nom
break;
// ...
</div></div>} // Fin du switch( flag )</div>} // Fin du while byte != -1
// Traitement de transformation
String nom = new String( nom_buffer ); |