Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Value file_to_map( Interpreter interpreter, final Value var1, final Value var2 )
- {
- return file_to_map( interpreter, var1, var2, DataTypes.TRUE_VALUE );
- }
- public static Value file_to_map( Interpreter interpreter, final Value var1, final Value var2, final Value var3 )
- {
- String filename = var1.toString();
- CompositeValue result = (CompositeValue) var2;
- boolean compact = var3.intValue() == 1;
- BufferedReader reader = DataFileCache.getReader( filename );
- if ( reader == null )
- {
- return DataTypes.FALSE_VALUE;
- }
- String[] data = null;
- result.clear();
- try
- {
- int line = 0;
- while ( ( data = FileUtilities.readData( reader ) ) != null )
- {
- line++;
- if ( data.length > 1 )
- {
- result.read( data, 0, compact, filename, line );
- }
- }
- }
- catch ( Exception e )
- {
- StringBuilder buffer = new StringBuilder( "Invalid line in data file" );
- if ( data != null )
- {
- buffer.append( ": \"" );
- for ( int i = 0; i < data.length; ++i )
- {
- if ( i > 0 )
- {
- buffer.append( '\t' );
- }
- buffer.append( data[ i ] );
- }
- buffer.append( "\"" );
- }
- // Print the bad data that caused the error
- Exception ex = interpreter.runtimeException( buffer.toString() );
- // If it's a ScriptException, we generated it ourself
- if ( e instanceof ScriptException )
- {
- // Print the bad data and the resulting error
- RequestLogger.printLine( ex.getMessage() );
- RequestLogger.printLine( e.getMessage() );
- }
- else
- {
- // Otherwise, print a stack trace
- StaticEntity.printStackTrace( e, ex.getMessage() );
- }
- return DataTypes.FALSE_VALUE;
- }
- finally
- {
- try
- {
- reader.close();
- }
- catch ( Exception e )
- {
- }
- }
- return DataTypes.TRUE_VALUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment