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;
}
jerseyAllRowswhich is created from CSVReader, which reads the Jersey transform from a file into InputStream, returns empty lines, and fileAllRowswhich is created from FileInputStream, which contains the same file that is sent to the T-shirt, returns 3 lines.
What does the file that Jersey2 reads create another InputStream?
I need to send a file to Jersey2 and parse it using OpenCSV
EDITED
If I convert the input jersey to String as follows:
InputStream is = new ByteArrayInputStream(IOUtils.toString(inputStream).getBytes());
reader = new CSVReader(new InputStreamReader(is), ',', '"', 0);
I get the lines. but this is a waste of memory :( Any idea?
source
share