I have the following code:
@POST
@Path("/csv")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String populateCSV(@FormDataParam("data") InputStream fileInputStream) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
File initialFile = new File("/Users/me/Downloads/file.csv");
InputStream targetStream = FileUtils.openInputStream(initialFile);
CSVReader reader = new CSVReader(new InputStreamReader(targetStream), ',', '"', 0);
CSVReader jerseyReader = new CSVReader(new InputStreamReader(fileInputStream), ',', '"', 0);
List<String[]> fileAllRows = reader.readAll();
List<String[]> jerseyAllRows = jerseyReader.readAll();
return null;
}
jerseyAllRows
which is created out of CSVReader
that reads Jersey conversion of File to InputStream returns empty lines, while fileAllRows
which is created out of a FileInputStream
that contains the same file that is being submitted to jersey, returns 3 lines.
What makes the way that Jersey2 reads file create a different InputStream?
I need to post a file to Jersey2 and be able to parse it with OpenCSV
EDITED
If I convert the jersey input stream into String like this:
InputStream is = new ByteArrayInputStream(IOUtils.toString(inputStream).getBytes());
reader = new CSVReader(new InputStreamReader(is), ',', '"', 0);
I do get lines. but that's a waste of memory :( Any idea?