gautamdudeja90 / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 1 forks source link

Fixed Length load fail #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?  If applicable, please provide a
mapping configuration and sample record input to recreate the problem.
1.I create a Stream records with 240 characters length and other and other 150 
characters length.
2.I try to load as Map<String,Object> BeanIO throws a InvalidRecordException, 
before processing 150 characters length record.
3.This is the stack trace.
co.com.gdsoft.gda.framework.core.FileProcessorException: 
org.beanio.InvalidRecordException: Invalid 'transacciones' record at line 1109
 ==> Invalid record length, expected minimum 240 characters
    at co.com.gdsoft.gda.framework.fixedlength.FixedLengthFileProcessor.load(FixedLengthFileProcessor.java:151)
    at co.com.bancodebogota.gda.plantillas.test.BaseTestCase.cargarArchivo(BaseTestCase.java:54)
    at co.com.bancodebogota.gda.plantillas.test.BaseTestCase.test(BaseTestCase.java:100)
    at co.com.bancodebogota.gda.plantillas.test.ExtractosTestCase.testExtractosCuentaAhorrosPDA(ExtractosTestCase.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at junit.framework.TestCase.runTest(TestCase.java:176)
    at junit.framework.TestCase.runBare(TestCase.java:141)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.beanio.InvalidRecordException: Invalid 'transacciones' record at 
line 1109
 ==> Invalid record length, expected minimum 240 characters
    at org.beanio.internal.parser.UnmarshallingContext.validate(UnmarshallingContext.java:196)
    at org.beanio.internal.parser.BeanReaderImpl.internalRead(BeanReaderImpl.java:105)
    at org.beanio.internal.parser.BeanReaderImpl.read(BeanReaderImpl.java:64)
    at co.com.gdsoft.gda.framework.fixedlength.FixedLengthFileProcessor.loadAllRecords(FixedLengthFileProcessor.java:165)
    at co.com.gdsoft.gda.framework.fixedlength.FixedLengthFileProcessor.load(FixedLengthFileProcessor.java:134)
    ... 22 more

What is the expected output? What do you see instead?
I expect Map<String, Object> of 150 characters record.

What version of BeanIO are you using? What JDK version?
1.6

Please provide any additional information below.

Original issue reported on code.google.com by andress...@gmail.com on 9 Feb 2013 at 9:04

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry, but your English is a little hard to follow.  Is the 'transacciones' 
record supposed to be 150 or 240 characters in length?  If 150, you may need to 
put minLength="150" on that record definition.

Original comment by kevin.s...@gmail.com on 12 Feb 2013 at 2:42

GoogleCodeExporter commented 9 years ago
Hello Kevin,

I'm Sorry, my English is not good, the problem is that there is an error when 
it tries to process a record 250 of 150 characters to another, for example I 
have the following stream.

<beanio xmlns="http://www.beanio.org/2012/03" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">

    <stream name="stream" format="fixedlength" strict="true">
        <record name="record1" class="map" occurs="0+">
            <field name="record" length="240" type="string" />
        </record>

        <record name="record2" class="map" occurs="2">
            <field name="record" length="150" type="string" />
        </record>
    </stream>
</beanio>

Then using a code like the following:

import java.io.InputStreamReader;

import org.beanio.BeanReader;
import org.beanio.StreamFactory;

public class Test {

    public static void main(String[] args) throws Exception {
        StreamFactory factory = StreamFactory.newInstance();
        factory.load(Test.class.getResourceAsStream("Stream.xml"));
        BeanReader in = factory
                .createReader(
                        "stream",
                        new InputStreamReader(
                                Test.class
                                        .getResourceAsStream("ExtractoCuentaAhorrosPlanoAmpliada.txt")));

        while (in.read() != null) {
        }
        in.close();
    }
}

BeanIO throws the following stack trace:

Exception in thread "main" org.beanio.InvalidRecordException: Invalid 'record1' 
record at line 1109
 ==> Invalid record length, expected minimum 240 characters
    at org.beanio.internal.parser.UnmarshallingContext.validate(UnmarshallingContext.java:196)
    at org.beanio.internal.parser.BeanReaderImpl.internalRead(BeanReaderImpl.java:105)
    at org.beanio.internal.parser.BeanReaderImpl.read(BeanReaderImpl.java:64)
    at Test.main(Test.java:18)

In line 1109 begins to use a record of 150 characters, but BeanIO throws 
InvalidRecordException, if you see the stream, the last two records must be 150 
characters.

Original comment by andress...@gmail.com on 12 Feb 2013 at 4:44

Attachments:

GoogleCodeExporter commented 9 years ago
Hello,

That is expected behavior.  Without any record identifying criteria defined, 
"record1" will continue to match because there is no finite maximum 
occurrences.  You either need to add a record identifying field (i.e. 
rid="true") to the record, or identify records based on their length.  For 
example, add ridLength="240" to record1 and ridLength="150" to record2 
(assuming you are using BeanIO 2.0.3).

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 12 Feb 2013 at 3:47

GoogleCodeExporter commented 9 years ago
<?xml version='1.0' encoding='UTF-8' ?>
<beanio xmlns="http://www.beanio.org/2012/03" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">

    <stream name="stream" format="fixedlength" strict="true">
        <record name="record1" class="map" occurs="0+" ridLength="240">
            <field name="record" length="240" type="string" />
        </record>

        <record name="record2" class="map" occurs="2" ridLength="150">
            <field name="record" length="150" type="string" />
        </record>
    </stream>
</beanio>

Wow!, BeanIO is amazing!, congratulations, great work, you saved my project, 
thank you very much.

Andrés Sánchez Lozano.

Original comment by andress...@gmail.com on 13 Feb 2013 at 2:02