Skip to content

Commit

Permalink
Merge pull request #1 from mehanika/read-from-inputstream
Browse files Browse the repository at this point in the history
Agregando metodo para procesar un archivo apartir del InputStream
  • Loading branch information
mehanika committed Jun 16, 2015
2 parents 2428f0a + 2ddc185 commit e8fe579
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences
#Tue Jun 16 12:47:52 CDT 2015
org.springsource.ide.eclipse.gradle.rootprojectloc=..
24 changes: 22 additions & 2 deletions dbf-reader/src/main/java/org/jamel/dbf/processor/DbfProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import org.jamel.dbf.DbfReader;
import org.jamel.dbf.exception.DbfException;
import org.jamel.dbf.structure.DbfDataType;
import org.jamel.dbf.structure.DbfField;
import org.jamel.dbf.structure.DbfHeader;
import org.jamel.dbf.utils.StringUtils;

import static org.jamel.dbf.utils.StringUtils.rightPad;

/**
Expand All @@ -35,6 +34,27 @@ public final class DbfProcessor {

private DbfProcessor() {
}

/**
*
* @param <T> Output type
* @param inputStream Input stream
* @param rowMapper Row mapper
* @return Mapped rows
* @throws DbfException
*/
public static <T> List<T> loadData(InputStream inputStream, DbfRowMapper<T> rowMapper) throws DbfException
{
try (DbfReader reader = new DbfReader(inputStream)) {
List<T> result = new ArrayList<>(reader.getRecordCount());
Object[] row;
while ((row = reader.nextRecord()) != null) {
result.add(rowMapper.mapRow(row));
}

return result;
}
}

public static <T> List<T> loadData(File dbf, DbfRowMapper<T> rowMapper) throws DbfException {
try (DbfReader reader = new DbfReader(dbf)) {
Expand Down

0 comments on commit e8fe579

Please sign in to comment.