Class CsvParser.AbstractDSL<D extends CsvParser.AbstractDSL<D>>
java.lang.Object
org.simpleflatmapper.lightningcsv.CsvParser.AbstractDSL<D>
- Direct Known Subclasses:
CsvParser.DSL,CsvParser.DSLYamlComment
- Enclosing class:
CsvParser
public abstract static class CsvParser.AbstractDSL<D extends CsvParser.AbstractDSL<D>>
extends Object
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected final org.simpleflatmapper.util.Function<? super CellConsumer,? extends CellConsumer> protected final charprotected final intprotected final intprotected final booleanprotected final charprotected final charprotected final intprotected final booleanprotected final CsvParser.AbstractDSL.StringPostProcessingprotected final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedAbstractDSL(char separatorChar, char quoteChar, char escapeChar, int bufferSize, int skip, int limit, int maxBufferSize, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing, org.simpleflatmapper.util.Function<? super CellConsumer, ? extends CellConsumer> cellConsumerWrapper, boolean yamlComment, boolean parallelReader, boolean specialisedCharConsumer) -
Method Summary
Modifier and TypeMethodDescriptionfinal intbufferSize(int size) set the size of the char buffer to read from.protected CharBuffercharBuffer(char[] content, int from, int to) protected CharBuffercharBuffer(Reader reader) protected CharBuffercharBuffer(CharSequence content) protected CharBuffercharBuffer(String content) protected final AbstractCharConsumercharConsumer(CharBuffer charBuffer) escape(char c) set the quote character.final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>>
Hfinal <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>>
Hfinal <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>>
HforEach(CharSequence content, H consumer) final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>>
Hprotected CellPreProcessorgetCellTransformer(TextFormat textFormat, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing) protected TextFormatprotected CellPreProcessorgetUnescapeCellTransformer(TextFormat textFormat) final org.simpleflatmapper.util.CloseableIterator<String[]>iterator(CharSequence content) final intlimit()limit(int limit) set the number of row to process.final intmaxBufferSize(int maxBufferSize) set the maximum size of the content the parser will handle before failing to avoid OOM.protected abstract DnewDSL(char separatorChar, char quoteChar, char escapeChar, int bufferSize, int skip, int limit, int maxBufferSize, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing, org.simpleflatmapper.util.Function<? super CellConsumer, ? extends CellConsumer> cellConsumerWrapper, boolean yamlComment, boolean parallelReader, boolean specialisedCharConsumer) on parsing from a reader the Reader will be fetched from a another thread.final <CC extends CellConsumer>
CCfinal <CC extends CellConsumer>
CCParse the content from the reader as a csv and call back the cellConsumer with the cell values.final <CC extends CellConsumer>
CCparse(CharSequence content, CC cellConsumer) final <CC extends CellConsumer>
CCfinal charquote()quote(char c) set the quote character.final CsvReaderreader(char[] chars, int from, int to) final CloseableCsvReaderfinal CsvReaderCreate a CsvReader and the specified reader.final CsvReaderreader(CharSequence content) final CsvReaderfinal org.simpleflatmapper.util.CloseableIterator<Row>rowIterator(File file) rowIterator(Reader reader) rowIterator(CharSequence content) rowIterator(String content) final <R> RrowStream(CharSequence content) final charseparator(char c) set the separator character.deactivate the parallelReader.final intskip()skip(int skip) set the number of line to skip.Deprecated.final <R> Rstream(CharSequence content)
-
Field Details
-
separatorChar
protected final char separatorChar -
quoteChar
protected final char quoteChar -
escapeChar
protected final char escapeChar -
bufferSize
protected final int bufferSize -
skip
protected final int skip -
limit
protected final int limit -
maxBufferSize
protected final int maxBufferSize -
stringPostProcessing
-
cellConsumerWrapper
protected final org.simpleflatmapper.util.Function<? super CellConsumer,? extends CellConsumer> cellConsumerWrapper -
yamlComment
protected final boolean yamlComment -
parallelReader
protected final boolean parallelReader -
specialisedCharConsumer
protected final boolean specialisedCharConsumer
-
-
Constructor Details
-
AbstractDSL
protected AbstractDSL() -
AbstractDSL
protected AbstractDSL(char separatorChar, char quoteChar, char escapeChar, int bufferSize, int skip, int limit, int maxBufferSize, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing, org.simpleflatmapper.util.Function<? super CellConsumer, ? extends CellConsumer> cellConsumerWrapper, boolean yamlComment, boolean parallelReader, boolean specialisedCharConsumer)
-
-
Method Details
-
parse
Parse the content from the reader as a csv and call back the cellConsumer with the cell values.- Type Parameters:
CC- the type of the cell consumer- Parameters:
reader- the readercellConsumer- the callback object for each cell value- Returns:
- cellConsumer
- Throws:
IOException- if and error occurs in the reader
-
parse
- Throws:
IOException
-
parse
public final <CC extends CellConsumer> CC parse(CharSequence content, CC cellConsumer) throws IOException - Throws:
IOException
-
parse
- Throws:
IOException
-
reader
Create a CsvReader and the specified reader. Will skip the number of specified rows.- Parameters:
reader- the content- Returns:
- a CsvReader on the reader.
- Throws:
IOException- if an io error occurs
-
reader
- Throws:
IOException
-
reader
- Throws:
IOException
-
reader
- Throws:
IOException
-
charBuffer
- Throws:
IOException
-
charBuffer
- Throws:
IOException
-
charBuffer
- Throws:
IOException
-
charBuffer
- Throws:
IOException
-
reader
- Throws:
IOException
-
iterator
- Throws:
IOException
-
iterator
- Throws:
IOException
-
iterator
- Throws:
IOException
-
iterator
public final org.simpleflatmapper.util.CloseableIterator<String[]> iterator(File file) throws IOException - Throws:
IOException
-
rowIterator
- Throws:
IOException
-
rowIterator
- Throws:
IOException
-
rowIterator
- Throws:
IOException
-
rowIterator
public final org.simpleflatmapper.util.CloseableIterator<Row> rowIterator(File file) throws IOException - Throws:
IOException
-
forEach
public final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>> H forEach(Reader reader, H consumer) throws IOException - Throws:
IOException
-
forEach
public final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>> H forEach(CharSequence content, H consumer) throws IOException - Throws:
IOException
-
forEach
public final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>> H forEach(String content, H consumer) throws IOException - Throws:
IOException
-
forEach
public final <H extends org.simpleflatmapper.util.CheckedConsumer<String[]>> H forEach(File file, H consumer) throws IOException - Throws:
IOException
-
stream
- Throws:
IOException
-
stream
- Throws:
IOException
-
stream
- Throws:
IOException
-
rowStream
- Throws:
IOException
-
rowStream
- Throws:
IOException
-
rowStream
- Throws:
IOException
-
stream
Deprecated.Use @see AbstractDSL#stream(File, Function).- Parameters:
file- the file- Returns:
- a stream of String[]
- Throws:
IOException
-
stream
- Throws:
IOException
-
rowStream
- Throws:
IOException
-
charConsumer
-
getTextFormat
-
getCellTransformer
protected CellPreProcessor getCellTransformer(TextFormat textFormat, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing) -
getUnescapeCellTransformer
-
maxBufferSize
public final int maxBufferSize() -
bufferSize
public final int bufferSize() -
limit
public final int limit() -
skip
public final int skip() -
separator
public final char separator() -
quote
public final char quote() -
separator
set the separator character. the default value is ','.- Parameters:
c- the new separator character- Returns:
- this
-
quote
set the quote character. the default value is '"'.- Parameters:
c- the quote character- Returns:
- this
-
escape
set the quote character. the default value is '"'.- Parameters:
c- the quote character- Returns:
- this
-
bufferSize
set the size of the char buffer to read from.- Parameters:
size- the size in bytes- Returns:
- this
-
skip
set the number of line to skip.- Parameters:
skip- number of line to skip.- Returns:
- this
-
limit
set the number of row to process. limit does not affect stream or iterator.- Parameters:
limit- number of row to process- Returns:
- this
-
parallelReader
on parsing from a reader the Reader will be fetched from a another thread. Use only if you have spare cores and the file is big enough.On java 8 and over it will use the ForkJoinPool by default if the number of core is greater than 1, otherwise it will create a new Thread every time.
On java 6 and 7 it will create a shared ExecutorService with the number of threads set to the number of cores if it is greater than 1, otherwise it will create a new Thread every time.
If you wish to customize the org.simpleflatmapper.util.ParallelReader further for example to specify which Executor to user or the size of the ring buffer or read buffer you will need to wrap the Reader manually.
- Returns:
- this
-
serialReader
deactivate the parallelReader.- Returns:
- this
-
disableSpecialisedCharConsumer
-
maxBufferSize
set the maximum size of the content the parser will handle before failing to avoid OOM.- Parameters:
maxBufferSize- the maximum size the buffer will grow, default 8M- Returns:
- this
-
newDSL
protected abstract D newDSL(char separatorChar, char quoteChar, char escapeChar, int bufferSize, int skip, int limit, int maxBufferSize, CsvParser.AbstractDSL.StringPostProcessing stringPostProcessing, org.simpleflatmapper.util.Function<? super CellConsumer, ? extends CellConsumer> cellConsumerWrapper, boolean yamlComment, boolean parallelReader, boolean specialisedCharConsumer)
-