Skip to content

Commit

Permalink
fix: nb char extraction without reading full line
Browse files Browse the repository at this point in the history
  • Loading branch information
lmanelphe committed Jan 23, 2024
1 parent 241a074 commit d6742b7
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ private String requeteFichierBrutalement(String idSource, BufferedReader br, int

StringBuilder requete=new StringBuilder();
int idLigne = nbBoucle * LIMIT_CHARGEMENT_BRUTAL_NB_LIGNE;
String line;
try {
line = br.readLine();
line = line.substring(0, Math.min(line.length(), LIMIT_CHARGEMENT_BRUTAL_NB_CHAR));
} catch (IOException e) {
throw new ArcException(e, ArcExceptionMessage.FILE_READ_FAILED, idSource);
}
if (line == null) {
throw new ArcException(ArcExceptionMessage.FILE_IS_EMPTY, idSource);
}
String line = readLineBrutal(idSource, br);
boolean start=true;
while (line != null && idLigne < (nbBoucle + 1) * LIMIT_CHARGEMENT_BRUTAL_NB_LIGNE) {
if (start)
Expand All @@ -83,6 +74,33 @@ private String requeteFichierBrutalement(String idSource, BufferedReader br, int
return requete.toString();

}

/**
* Retourne la ligne lue dans la limite du nombre de caractères
* @param idSource du fichier chargé
* @param br reader ouvert sur le fichier
* @return
* @throws ArcException
*/
private String readLineBrutal(String idSource, BufferedReader br) throws ArcException {
char[] buffer = new char[LIMIT_CHARGEMENT_BRUTAL_NB_CHAR];
int size = 0;
int offset = 0;
try {
while (size != -1 && offset < LIMIT_CHARGEMENT_BRUTAL_NB_CHAR) {
size = br.read(buffer, offset, LIMIT_CHARGEMENT_BRUTAL_NB_CHAR - offset);
offset += size;
}
} catch (IOException e) {
throw new ArcException(e, ArcExceptionMessage.FILE_READ_FAILED, idSource);
}
if (size == 0) {
throw new ArcException(ArcExceptionMessage.FILE_IS_EMPTY, idSource);
}

String line = new String(buffer, 0, size);
return line;
}

/** Calcule la norme. Retourne (par référence) la norme dans normeOk[0] et la validité dans validiteOk[0].
* @throws IOException
Expand Down

0 comments on commit d6742b7

Please sign in to comment.