public static Value freadval ( Value fval , Value indexVal ) { ValueList result = new ValueList ( ) ; try { File file = getFile ( fval ) ; long index = indexVal . intValue ( null ) ; SeqValue lineCells = new SeqValue ( ) ; boolean success = false ; try { CsvParser parser = new CsvParser ( new CsvValueBuilder ( ) { @ Override public Value createValue ( String value ) throws Exception { return CSV . createValue ( "CSV" , "freadval" , value ) ; } } ) ; CsvResult res = parser . parseValues ( getLine ( file , index ) ) ; if ( ! res . dataOk ( ) ) { lastError = res . getErrorMsg ( ) ; success = false ; } else { lineCells . values . addAll ( res . getValues ( ) ) ; success = true ; } } catch ( Exception e ) { success = false ; lastError = e . getMessage ( ) ; // OK } result . add ( new BooleanValue ( success ) ) ; result . add ( lineCells ) ; } catch ( Exception e ) { lastError = e . toString ( ) ; result = new ValueList ( ) ; result . add ( new BooleanValue ( false ) ) ; result . add ( new NilValue ( ) ) ; } return new TupleValue ( result ) ; }
Read a CSV live as a seq of ? in VDM