You can construct an InputStreamReader from that InputStream

new InputStreamReader(myInputStream, encoding)

Where myInputStream is your InputStream and encoding is a String that defines the encoding used by your datasource.

You can call your CSVReader like this:

new CSVReader(new InputStreamReader(myInputStream, encoding));
Answer from oers on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-csv › apidocs › org › apache › commons › csv › CSVParser.html
CSVParser (Apache Commons CSV 1.14.2-SNAPSHOT API)
public static CSVParser parse · (InputStream inputStream, Charset charset, CSVFormat format) throws IOException · Creates a CSV parser using the given CSVFormat. If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.
🌐
Java2s
java2s.com › example › java-utility-method › csv-file-parse › parsecsv-inputstream-csvinput-3765b.html
Java CSV File Parse parseCsv(InputStream csvInput)
*/ public static List<List<String>> parseCsv(InputStream csvInput) { return parseCsv(csvInput, DEFAULT_CSV_SEPARATOR); } /** * CSV content parser. Convert an InputStream with the CSV contents to a two-dimensional List * of Strings representing the rows and columns of the CSV.
🌐
Oracle
docs.oracle.com › middleware › 1213 › adf › api-reference-model › oracle › adf › model › adapter › dataformat › csv › CSVParser.html
CSVParser (Oracle Fusion Middleware Java API Reference for Oracle ADF Model)
public CSVParser(java.io.InputStream pInputStream) throws java.lang.Exception · Constructor · Parameters: pInputStream - CSV input stream · Throws: java.lang.Exception - any error occurred · public CSVParser(java.io.InputStream pInputStream, java.lang.String pEnc) throws java.lang.Exception ·
🌐
Apache Commons
commons.apache.org › proper › commons-csv › jacoco › org.apache.commons.csv › CSVParser.java.html
CSVParser.java - Apache Commons
* @since 1.5 */ public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) throws IOException { return parse(new InputStreamReader(inputStream, Charsets.toCharset(charset)), format); } /** * Creates and returns a parser for the given {@link Path}, which the caller MUST close.
🌐
Java Tips
javatips.net › api › org.apache.commons.csv.csvparser
Java Examples for org.apache.commons.csv.CSVParser
The following java examples will help you to understand the usage of org.apache.commons.csv.CSVParser. These source code samples are taken from different open source projects. ... @Override public void map(Text key, BytesWritable value, Context context) throws IOException, InterruptedException { ByteArrayInputStream inputStream = new ByteArrayInputStream(value.getBytes()); int n = value.getLength(); byte[] bytes = new byte[n]; inputStream.read(bytes, 0, n); CSVParser parser = CSVParser.parse(new String(bytes), CSVFormat.DEFAULT); try { for (CSVRecord csvRecord : parser) { for (String string : csvRecord) { word.set(string); context.write(word, one); Counter counter = context.getCounter(CountersEnum.class.getName(), CountersEnum.INPUT_WORDS.toString()); counter.increment(1); } } } catch (Exception e) { } }
🌐
Simplesolution
simplesolution.dev › java-read-and-parse-csv-file-using-apache-commons-csv
Read and Parse CSV File in Java using Apache Commons CSV
args) { try { String csvFileName = "D:\\SimpleSolution\\Customers.csv"; CSVFormat csvFormat = CSVFormat.DEFAULT.withFirstRecordAsHeader().withIgnoreHeaderCase(); InputStream inputStream = new FileInputStream(csvFileName); CSVParser csvParser = CSVParser.parse(inputStream, StandardCharsets.UTF_8, csvFormat); for(CSVRecord csvRecord : csvParser) { String firstName = csvRecord.get("First Name"); String lastName = csvRecord.get("Last Name"); String email = csvRecord.get("Email"); String phoneNumber = csvRecord.get("Phone Number"); System.out.println(firstName + "," + lastName + "," + email + "," + phoneNumber); } inputStream.close(); csvParser.close(); } catch (IOException e) { e.printStackTrace(); } } } The output is:
🌐
Apache Commons
commons.apache.org › proper › commons-csv › apidocs › src-html › org › apache › commons › csv › CSVParser.html
Source code - Apache Commons
345 * @since 1.5 346 */ 347 public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) 348 throws IOException { 349 return parse(new InputStreamReader(inputStream, Charsets.toCharset(charset)), format); 350 } 351 352 /** 353 * Creates and returns a parser for the given {@link Path}, which the caller MUST close.
Find elsewhere
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
Bennadel
bennadel.com › blog › 2241-parsing-csv-data-with-an-input-stream-and-a-finite-state-machine.htm
Parsing CSV Data With An Input Stream And A Finite State Machine
April 21, 2020 - ---> <cfset var local = {} /> <!--- Even if the document has no data, we will, at the very least, start and end the document. ---> <cfset this.publish( "startDocument" ) /> <!--- Read the first character in the CSV input stream. ---> <cfset local.nextByte = variables.inputStream.read() /> <!--- The input stream will be providing a single byte at a time.
🌐
SAP
help.sap.com › doc › 02d5152884b34821a06408495ba0b771 › 1905 › en-US › de › hybris › platform › util › CSVReader.html
CSVReader (hybris Commerce Suite 1905)
Create the Reader csvreader = new CSVReader(inputStream, null ); //null for default encoding Use the constructor to set the encoding and the stream.
🌐
GitHub
github.com › motech › test › blob › master › src › test › java › org › motechproject › whp › mtraining › csv › parser › CsvParserTest.java
test/src/test/java/org/motechproject/whp/mtraining/csv/parser/CsvParserTest.java at master · motech/test
List<CourseStructureCsvRequest> actualCourseCsvContent = csvParser.parse(mockMultipartFile, CourseStructureCsvRequest.class); ... public void shouldParseGivenCsvFileToGivenBeanTypeIgnoringExtraColumnOfCsv() throws IOException { String resourceName = "fileWithExtraHeading.csv"; File file = new File("./src/test/resources/fileWithExtraHeading.csv"); InputStream inputStream = new FileInputStream(file);
Author   motech
🌐
Stack Overflow
stackoverflow.com › questions › 51744690 › apache-commons-csv-parser
java 8 - Apache commons CSV parser - Stack Overflow
CSVParser.parse(inputStream, Charset.defaultCharset(), CSVFormat.DEFAULT .withTrim() .withHeader() // note, do not specify any columns here )
🌐
Stack Overflow
stackoverflow.com › questions › 39520459 › convert-csvwriter-to-inputstream
csv - Convert CSVwriter to inputstream - Stack Overflow
May 28, 2020 - The solution is to use InputStreamReader to read the file and pass that stream to Buffered reader and read line by line or as you want.
🌐
Wordpress
ivarconr.wordpress.com › 2013 › 11 › 21 › streaming-csv-files-with-the-java-8-stream-api
Streaming CSV files with the Stream API in Java 8 | Developer writing about stuff
November 23, 2013 - InputStream is = new FileInputStream(new File("persons.csv")); BufferedReader br = new BufferedReader(new InputStreamReader(is)); List<Person> persons = br.lines() .substream(1) .map(mapToPerson) .filter(person -> person.getAge() > 17) .limit(50) .collect(toList());
🌐
Mkyong
mkyong.com › home › java › how to read and parse csv file in java
How to read and parse CSV file in Java - Mkyong.com
December 26, 2020 - package com.mkyong.io.csv; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.net.URL; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; public class CsvParserSimple { private static final char DEFAULT_SEPARATOR = ','; private static final char DOUBLE_QUOTES = '"'; private static final char DEFAULT_QUOTE_CHAR = DOUBLE_QUOTES; private static final String NEW_LINE = "\n"; private boolean isMultiLine = false; private String pendingField = ""; private String[] pendingFieldLine = new String[]{}; public static void main(String[] args) throws Exception { // loads CSV file from the resource folder.
🌐
Baeldung
baeldung.com › home › kotlin › kotlin io › read and write csv files with kotlin
Read and Write CSV Files With Kotlin | Baeldung on Kotlin
March 19, 2024 - fun readStrictCsv(inputStream: InputStream): List<TaxableGood> = csvReader().open(inputStream) { readAllWithHeaderAsSequence().map { TaxableGood( it["Index"]!!.trim().toInt(), it["Item"]!!.trim(), BigDecimal(it["Cost"]), BigDecimal(it["Tax"]), BigDecimal(it["Total"]) ) }.toList() }