All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.db.StreamDecodesScriptReader Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
package decodes.db;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Optional;

/**
 * Read a decodes script from a text file.
 * Primarily used for testing decodes scripts.
 */
public class StreamDecodesScriptReader implements DecodesScriptReader
{
    private int lineNumber = 1;
    private BufferedReader reader = null;

    public StreamDecodesScriptReader(InputStream stream)
    {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    @Override
    public Optional nextStatement(DecodesScript script) throws IOException
    {
        FormatStatement fs = null;
        String line = reader.readLine();
        if ( line != null)
        {
            int firstColon = line.indexOf(":");
            if (firstColon < 0 )
            {
                throw new IOException("Statement on line " + lineNumber + " is not a label separated by a colon.");
            }
            String label = line.substring(0, firstColon);
            String statement = line.substring(firstColon+1);
            fs = new FormatStatement(script, lineNumber);
            lineNumber++;
            fs.label = label;
            fs.format = statement.trim();
        }
        return Optional.ofNullable(fs);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy