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

nl.praegus.fitnesse.slim.fixtures.FixedLengthFileFixture Maven / Gradle / Ivy

There is a newer version: 1.38.1
Show newest version
package nl.praegus.fitnesse.slim.fixtures;

import nl.hsac.fitnesse.fixture.slim.FileFixture;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class FixedLengthFileFixture extends FileFixture {
    private List lines;

    public FixedLengthFileFixture(String fileName) {
        loadFile(fileName);
    }

    public void loadFile(String fileName) {
        List lines = new ArrayList<>();
        try {
            Stream stream = Files.lines(Paths.get(getFilePathFromWikiUrl(fileName)));
            lines = stream.collect(Collectors.toList());
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        this.lines = lines;
    }

    public String valueOnPositionWithLengthOnLine(int startPos, int length, int lineNumber) {
        String line = lines.get(lineNumber-1);
        return line.substring(startPos-1, startPos + length -1);
    }

    public String trimmedValueOnPositionWithLengthOnLine(int startPos, int length, int lineNumber) {
        return valueOnPositionWithLengthOnLine(startPos, length, lineNumber).trim();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy