Skip to content

Commit

Permalink
Atualiza Retorno Boleto Reflection para JDK 17 e pra usar Files.readA…
Browse files Browse the repository at this point in the history
…llLines

Signed-off-by: Manoel Campos <[email protected]>
  • Loading branch information
manoelcampos committed Sep 7, 2023
1 parent 23f68d6 commit 83a42ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions comportamentais/strategy/retorno-boleto-reflection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -25,12 +24,12 @@ public interface LeituraRetorno {
List<ProcessaCampoArquivo<?>> getProcessadoresCampos();

default List<Boleto> lerArquivo(URI caminhoArquivo) {
try (var reader = Files.newBufferedReader(Paths.get(caminhoArquivo))){
String line;
List<Boleto> boletos = new ArrayList<>();
while((line = reader.readLine()) != null){
String[] vetor = line.split(";");
Boleto boleto = new Boleto();
try {
var listaLinhas = Files.readAllLines(Paths.get(caminhoArquivo));
var boletos = new ArrayList<Boleto>();
for (String linha : listaLinhas) {
String[] vetor = linha.split(";");
var boleto = new Boleto();
for (int i = 0; i < getProcessadoresCampos().size(); i++) {
setCampoBoleto(i, boleto, vetor[i]);
}
Expand All @@ -46,7 +45,7 @@ default List<Boleto> lerArquivo(URI caminhoArquivo) {
private void setCampoBoleto(int idxCampo, Boleto boleto, String valor) {
ProcessaCampoArquivo processador = getProcessadoresCampos().get(idxCampo);
try {
Field field = boleto.getClass().getDeclaredField(processador.getCampo());
var field = boleto.getClass().getDeclaredField(processador.getCampo());
field.setAccessible(true);
field.set(boleto, processador.converter(valor));
} catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) {
Expand Down

0 comments on commit 83a42ef

Please sign in to comment.