From 46dd13bea18f0720f0e6a815e33f69a6ce34607f Mon Sep 17 00:00:00 2001 From: "rafael.henrique" Date: Mon, 21 May 2018 15:10:18 +0000 Subject: [PATCH] Arquivo de Remessa CNAB bug#9100 bug#9803 bug#10881 dev:rafael.henrique qua:Marcelo git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/GeneradorBoletosCNAB/trunk@81983 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ArquivoRemessaBancoBrasil.java | 1 + .../layouts/AbstractFlatFile.java | 39 ++++++++++++++----- .../ventaboletos/utils/NossoNumeroUtils.java | 6 +-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/blocos/bancobrasil/ArquivoRemessaBancoBrasil.java b/src/com/rjconsultores/ventaboletos/blocos/bancobrasil/ArquivoRemessaBancoBrasil.java index 37fd6f36f..9811b7747 100644 --- a/src/com/rjconsultores/ventaboletos/blocos/bancobrasil/ArquivoRemessaBancoBrasil.java +++ b/src/com/rjconsultores/ventaboletos/blocos/bancobrasil/ArquivoRemessaBancoBrasil.java @@ -26,6 +26,7 @@ public class ArquivoRemessaBancoBrasil extends ArquivoRemessaItem { if(((CabecalhoRemessaBancoBrasil) cabecalhoRemessa).getCabecalhoLoteRemessaBancoBrasil() != null){ qteRegistroArq++; qteRegistroLote++; + loteCount++; }else{ throw new RuntimeException("Falta cabecalho tipo: " + CabecalhoRemessaBancoBrasil.class.getName()); } diff --git a/src/com/rjconsultores/ventaboletos/layouts/AbstractFlatFile.java b/src/com/rjconsultores/ventaboletos/layouts/AbstractFlatFile.java index 5b392d145..039ba335a 100644 --- a/src/com/rjconsultores/ventaboletos/layouts/AbstractFlatFile.java +++ b/src/com/rjconsultores/ventaboletos/layouts/AbstractFlatFile.java @@ -1,11 +1,17 @@ package com.rjconsultores.ventaboletos.layouts; +import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -106,8 +112,9 @@ public abstract class AbstractFlatFile{ try { - in = ClassLoaders.getResourceAsStream(cfgFile.getPath(), this.getClass()); - + //in = ClassLoaders.getResourceAsStream(cfgFile.getPath(), this.getClass()); + in = getClass().getResourceAsStream(cfgFile.getPath()); + File config = File.createTempFile(cfgFile.getTemp(), null); copyInputStreamToFile(in, config); @@ -139,16 +146,29 @@ public abstract class AbstractFlatFile{ public void copyInputStreamToFile(InputStream initialStream, File targetFile) throws IOException { - OutputStream outStream = new FileOutputStream(targetFile); - - byte[] buffer = new byte[8 * 1024]; +// OutputStream outStream = new FileOutputStream(targetFile); +// +// byte[] buffer = new byte[8 * 1024]; +// int bytesRead; +// while ((bytesRead = initialStream.read(buffer)) != -1) { +// outStream.write(buffer, 0, bytesRead); +// } +// +// IOUtils.closeQuietly(initialStream); +// IOUtils.closeQuietly(outStream); + + Reader reader = new BufferedReader(new InputStreamReader(initialStream)); + Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), "Cp1252")); + + char[] buffer = new char[8 * 1024]; int bytesRead; - while ((bytesRead = initialStream.read(buffer)) != -1) { - outStream.write(buffer, 0, bytesRead); + while ((bytesRead = reader.read(buffer)) != -1){ + writer.write(buffer, 0, bytesRead); } IOUtils.closeQuietly(initialStream); - IOUtils.closeQuietly(outStream); + IOUtils.closeQuietly(reader); + IOUtils.closeQuietly(writer); } /** @@ -297,7 +317,8 @@ public abstract class AbstractFlatFile{ "Arquivo TXT a ser importado nulo!")); } - FileUtils.writeLines(arquivoRemessaFisico, this.lines, "\r\n"); + FileUtils.writeLines(arquivoRemessaFisico, "Cp1252", this.lines, "\r\n"); + //FileUtils.writeLines(file, encoding, lines, lineEnding); } protected void writeLines() throws IOException{ diff --git a/src/com/rjconsultores/ventaboletos/utils/NossoNumeroUtils.java b/src/com/rjconsultores/ventaboletos/utils/NossoNumeroUtils.java index b9f7900a9..534026111 100644 --- a/src/com/rjconsultores/ventaboletos/utils/NossoNumeroUtils.java +++ b/src/com/rjconsultores/ventaboletos/utils/NossoNumeroUtils.java @@ -234,15 +234,15 @@ public class NossoNumeroUtils { public static boolean validaNossoNumero(String nossoNumero, BancoLayout bancoLayout){ - if(BancoLayout.BRADESCO_400_Envio.equals(bancoLayout) && nossoNumero.length() == 12 ){ + if(BancoLayout.BRADESCO_400_Envio.equals(bancoLayout) && nossoNumero.length() == 13 ){ return Boolean.TRUE; } - if(BancoLayout.ITAU_400_Envio.equals(bancoLayout) && nossoNumero.length() == 9 ){ + if(BancoLayout.ITAU_400_Envio.equals(bancoLayout) && nossoNumero.length() == 10 ){ return Boolean.TRUE; } - if(BancoLayout.BB_240_Envio.equals(bancoLayout)){ + if(BancoLayout.BB_240_Envio.equals(bancoLayout) && (nossoNumero.length() == 13 || nossoNumero.length() == 17)){ return Boolean.TRUE; }