com.tecacet.finance.service.stock.yahoo.YahooSplitParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfapi Show documentation
Show all versions of jfapi Show documentation
JFApi connects to various Web Services that provide financial data such as stock prices,
splits, dividends, and FX rates.
package com.tecacet.finance.service.stock.yahoo;
import com.tecacet.finance.model.Split;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class YahooSplitParser {
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public List parse(InputStream is) throws IOException {
List splits = new ArrayList<>();
BufferedReader br = new BufferedReader(new InputStreamReader(is, Charset.defaultCharset()));
String line = br.readLine(); //skip header
while ((line = br.readLine()) != null) {
splits.add(parse(line));
}
br.close();
return splits;
}
public Split parse(String line) {
String[] tokens = line.split(",");
LocalDate date = LocalDate.parse(tokens[0].trim(), formatter);
String[] splitString = tokens[1].trim().split(":");
return new Split(date, Integer.parseInt(splitString[1]), Integer.parseInt(splitString[0]));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy