public void setFields ( DBFField [ ] fields ) { if ( this . closed ) { throw new IllegalStateException ( "You can not set fields to a closed DBFWriter" ) ; } if ( this . header . fieldArray != null ) { throw new DBFException ( "Fields has already been set" ) ; } if ( fields == null || fields . length == 0 ) { throw new DBFException ( "Should have at least one field" ) ; } for ( int i = 0 ; i < fields . length ; i ++ ) { if ( fields [ i ] == null ) { throw new DBFException ( "Field " + i + " is null" ) ; } } this . header . fieldArray = new DBFField [ fields . length ] ; for ( int i = 0 ; i < fields . length ; i ++ ) { this . header . fieldArray [ i ] = new DBFField ( fields [ i ] ) ; } try { if ( this . raf != null && this . raf . length ( ) == 0 ) { // this is a new/non-existent file. So write header before proceeding this . header . write ( this . raf ) ; } } catch ( IOException e ) { throw new DBFException ( "Error accesing file:" + e . getMessage ( ) , e ) ; } }
Sets fields definition