Skip to content

Commit

Permalink
Merge pull request #139 from abes-esr/develop
Browse files Browse the repository at this point in the history
merge dev to test
  • Loading branch information
pierre-maraval authored Nov 25, 2024
2 parents bbeeaf2 + 7b02fb4 commit 9deaa5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>fr.abes</groupId>
<artifactId>kbart2kafka</artifactId>
<version>1.0.0</version>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>kbart2kafka</name>
<description>chargement d'un fichier kbart dans kafka</description>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/abes/kbart2kafka/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.abes.kbart2kafka.dto.LigneKbartDto;
import fr.abes.kbart2kafka.exception.IllegalDateException;
import fr.abes.kbart2kafka.exception.IllegalFileFormatException;
import fr.abes.kbart2kafka.utils.CheckFiles;
import fr.abes.kbart2kafka.utils.PUBLICATION_TYPE;
import fr.abes.kbart2kafka.utils.Utils;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -71,6 +72,7 @@ private void executeMultiThread(File fichier) throws IllegalFileFormatException
ThreadContext.put("package", fichier.getName() + ";" + cpt.get());
String[] tsvElementsOnOneLine = ligneKbart.split("\t");
try {
CheckFiles.isValidUtf8(ligneKbart);
kbartsToSend.add(mapper.writeValueAsString(constructDto(tsvElementsOnOneLine, cpt.get(), nbLignesFichier)));
} catch (IllegalDateException | IllegalFileFormatException | JsonProcessingException e) {
log.error("Erreur dans le fichier en entrée à la ligne " + cpt.get() + " : " + e.getMessage());
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/fr/abes/kbart2kafka/utils/CheckFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;

@Slf4j
public class CheckFiles {
Expand Down Expand Up @@ -94,4 +97,13 @@ public static void verifyFile(File file, String header) throws IllegalFileFormat
detectTabulations(file);
detectHeaderPresence(header, file, isBypassOptionPresent);
}

public static void isValidUtf8(String input) throws IllegalFileFormatException {
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
try {
decoder.decode(java.nio.ByteBuffer.wrap(input.getBytes(StandardCharsets.UTF_8)));
} catch (CharacterCodingException e) {
throw new IllegalFileFormatException("le fichier contient des caracters qui ne sont pas en UTF8");
}
}
}

0 comments on commit 9deaa5a

Please sign in to comment.