Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5625E200B12 for ; Sun, 29 May 2016 04:24:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 54AF4160A1A; Sun, 29 May 2016 02:24:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DE1AC160A3D for ; Sun, 29 May 2016 04:24:53 +0200 (CEST) Received: (qmail 24483 invoked by uid 500); 29 May 2016 02:24:53 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 24474 invoked by uid 99); 29 May 2016 02:24:53 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 May 2016 02:24:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 721D51A0ADC for ; Sun, 29 May 2016 02:24:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.426 X-Spam-Level: X-Spam-Status: No, score=-0.426 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id zNwvL-KqE-r6 for ; Sun, 29 May 2016 02:24:23 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTP id BA40B60CD2 for ; Sun, 29 May 2016 02:24:10 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id B3355E59D0 for ; Sun, 29 May 2016 02:24:07 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 3CC6E3A17FD for ; Sun, 29 May 2016 02:24:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r989464 [5/46] - in /websites/production/commons/content/proper/commons-csv: ./ apidocs/ apidocs/org/apache/commons/csv/ apidocs/org/apache/commons/csv/class-use/ apidocs/resources/ apidocs/src-html/org/apache/commons/csv/ archives/ css/ ja... Date: Sun, 29 May 2016 02:24:05 -0000 To: notifications@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160529022407.3CC6E3A17FD@svn01-us-west.apache.org> archived-at: Sun, 29 May 2016 02:24:56 -0000 Modified: websites/production/commons/content/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html ============================================================================== --- websites/production/commons/content/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html (original) +++ websites/production/commons/content/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html Sun May 29 02:24:04 2016 @@ -1,703 +1,625 @@ - - - - - - -CSVParser (Apache Commons CSV 1.3 API) - - - - - - - - - - - -
-
org.apache.commons.csv
-

Class CSVParser

-
-
- -
-
    -
  • -
    -
    All Implemented Interfaces:
    -
    Closeable, AutoCloseable, Iterable<CSVRecord>
    -
    -
    -
    -
    public final class CSVParser
    -extends Object
    -implements Iterable<CSVRecord>, Closeable
    -
    Parses CSV files according to the specified format. - - Because CSV appears in many different dialects, the parser supports many formats by allowing the - specification of a CSVFormat. - - The parser works record wise. It is not possible to go back, once a record has been parsed from the input stream. - -

    Creating instances

    -

    - There are several static factory methods that can be used to create instances for various types of resources: -

    - -

    - Alternatively parsers can also be created by passing a Reader directly to the sole constructor. - - For those who like fluent APIs, parsers can be created using CSVFormat.parse(java.io.Reader) as a shortcut: -

    -
    - for(CSVRecord record : CSVFormat.EXCEL.parse(in)) {
    -     ...
    - }
    - 
    - -

    Parsing record wise

    -

    - To parse a CSV input from a file, you write: -

    - -
    - File csvData = new File("/path/to/csv");
    - CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180);
    - for (CSVRecord csvRecord : parser) {
    -     ...
    - }
    - 
    - -

    - This will read the parse the contents of the file using the - RFC 4180 format. -

    - -

    - To parse CSV input in a format like Excel, you write: -

    - -
    - CSVParser parser = CSVParser.parse(csvData, CSVFormat.EXCEL);
    - for (CSVRecord csvRecord : parser) {
    -     ...
    - }
    - 
    - -

    - If the predefined formats don't match the format at hands, custom formats can be defined. More information about - customising CSVFormats is available in CSVFormat JavaDoc. -

    - -

    Parsing into memory

    -

    - If parsing record wise is not desired, the contents of the input can be read completely into memory. -

    - -
    - Reader in = new StringReader("a;b\nc;d");
    - CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
    - List<CSVRecord> list = parser.getRecords();
    - 
    - -

    - There are two constraints that have to be kept in mind: -

    - -
      -
    1. Parsing into memory starts at the current position of the parser. If you have already parsed records from - the input, those records will not end up in the in memory representation of your CSV data.
    2. -
    3. Parsing into memory may consume a lot of system resources depending on the input. For example if you're - parsing a 150MB file of CSV data the contents will be read completely into memory.
    4. -
    - -

    Notes

    -

    - Internal parser state is completely covered by the format and the reader-state. -

    -
    -
    Version:
    -
    $Id: CSVParser.java 1742466 2016-05-05 19:55:37Z britter $
    -
    See Also:
    -
    package documentation for more details
    -
    -
  • -
-
-
- -
-
-
    -
  • - -
      -
    • - - -

      Constructor Detail

      - - - -
        -
      • -

        CSVParser

        -
        public CSVParser(Reader reader,
        -                 CSVFormat format)
        -          throws IOException
        -
        Customized 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. -

        -
        -
        Parameters:
        -
        reader - a Reader containing CSV-formatted input. Must not be null.
        -
        format - the CSVFormat used for CSV parsing. Must not be null.
        -
        Throws:
        -
        IllegalArgumentException - If the parameters of the format are inconsistent or if either reader or format are null.
        -
        IOException - If there is a problem reading the header or skipping the first record
        -
        -
      • -
      - - - -
        -
      • -

        CSVParser

        -
        public CSVParser(Reader reader,
        -                 CSVFormat format,
        -                 long characterOffset,
        -                 long recordNumber)
        -          throws IOException
        -
        Customized 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. -

        -
        -
        Parameters:
        -
        reader - a Reader containing CSV-formatted input. Must not be null.
        -
        format - the CSVFormat used for CSV parsing. Must not be null.
        -
        characterOffset - Lexer offset when the parser does not start parsing at the beginning of the source.
        -
        recordNumber - The next record number to assign
        -
        Throws:
        -
        IllegalArgumentException - If the parameters of the format are inconsistent or if either reader or format are null.
        -
        IOException - If there is a problem reading the header or skipping the first record
        -
        Since:
        -
        1.1
        -
        -
      • -
      -
    • -
    - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        parse

        -
        public static CSVParser parse(File file,
        -                              Charset charset,
        -                              CSVFormat format)
        -                       throws IOException
        -
        Creates a parser for the given File. - -

        Note: This method internally creates a FileReader using - FileReader.FileReader(java.io.File) which in turn relies on the default encoding of the JVM that - is executing the code. If this is insufficient create a URL to the file and use - parse(URL, Charset, CSVFormat)

        -
        -
        Parameters:
        -
        file - a CSV file. Must not be null.
        -
        charset - A charset
        -
        format - the CSVFormat used for CSV parsing. Must not be null.
        -
        Returns:
        -
        a new parser
        -
        Throws:
        -
        IllegalArgumentException - If the parameters of the format are inconsistent or if either file or format are null.
        -
        IOException - If an I/O error occurs
        -
        -
      • -
      - - - -
        -
      • -

        parse

        -
        public static CSVParser parse(String string,
        -                              CSVFormat format)
        -                       throws IOException
        -
        Creates a parser for the given String.
        -
        -
        Parameters:
        -
        string - a CSV string. Must not be null.
        -
        format - the CSVFormat used for CSV parsing. Must not be null.
        -
        Returns:
        -
        a new parser
        -
        Throws:
        -
        IllegalArgumentException - If the parameters of the format are inconsistent or if either string or format are null.
        -
        IOException - If an I/O error occurs
        -
        -
      • -
      - - - -
        -
      • -

        parse

        -
        public static CSVParser parse(URL url,
        -                              Charset charset,
        -                              CSVFormat format)
        -                       throws IOException
        -
        Creates a parser for the given URL. - -

        - If you do not read all records from the given url, you should call close() on the parser, unless - you close the url. -

        -
        -
        Parameters:
        -
        url - a URL. Must not be null.
        -
        charset - the charset for the resource. Must not be null.
        -
        format - the CSVFormat used for CSV parsing. Must not be null.
        -
        Returns:
        -
        a new parser
        -
        Throws:
        -
        IllegalArgumentException - If the parameters of the format are inconsistent or if either url, charset or format are null.
        -
        IOException - If an I/O error occurs
        -
        -
      • -
      - - - - - - - -
        -
      • -

        getCurrentLineNumber

        -
        public long getCurrentLineNumber()
        -
        Returns the current line number in the input stream. - -

        - ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to - the record number. -

        -
        -
        Returns:
        -
        current line number
        -
        -
      • -
      - - - -
        -
      • -

        getHeaderMap

        -
        public Map<String,IntegergetHeaderMap()
        -
        Returns a copy of the header map that iterates in column order. -

        - The map keys are column names. The map values are 0-based indices. -

        -
        -
        Returns:
        -
        a copy of the header map that iterates in column order.
        -
        -
      • -
      - - - -
        -
      • -

        getRecordNumber

        -
        public long getRecordNumber()
        -
        Returns the current record number in the input stream. - -

        - ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to - the line number. -

        -
        -
        Returns:
        -
        current record number
        -
        -
      • -
      - - - -
        -
      • -

        getRecords

        -
        public List<CSVRecordgetRecords()
        -                           throws IOException
        -
        Parses the CSV input according to the given format and returns the content as a list of - CSVRecords. - -

        - The returned content starts at the current parse-position in the stream. -

        -
        -
        Returns:
        -
        list of CSVRecords, may be empty
        -
        Throws:
        -
        IOException - on parse error or input read-failure
        -
        -
      • -
      - - - -
        -
      • -

        isClosed

        -
        public boolean isClosed()
        -
        Gets whether this parser is closed.
        -
        -
        Returns:
        -
        whether this parser is closed.
        -
        -
      • -
      - - - -
        -
      • -

        iterator

        -
        public Iterator<CSVRecorditerator()
        -
        Returns an iterator on the records. - -

        IOExceptions occurring during the iteration are wrapped in a - RuntimeException. - If the parser is closed a call to next() will throw a - NoSuchElementException.

        -
        -
        Specified by:
        -
        iterator in interface Iterable<CSVRecord>
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - -

Copyright © 2016 The Apache Software Foundation. All rights reserved.

- + + + + + +CSVParser (Apache Commons CSV 1.4 API) + + + + + + + + + + +
+
org.apache.commons.csv
+

Class CSVParser

+
+
+ +
+
    +
  • +
    +
    All Implemented Interfaces:
    +
    Closeable, AutoCloseable, Iterable<CSVRecord>
    +
    +
    +
    +
    public final class CSVParser
    +extends Object
    +implements Iterable<CSVRecord>, Closeable
    +
    Parses CSV files according to the specified format. + + Because CSV appears in many different dialects, the parser supports many formats by allowing the + specification of a CSVFormat. + + The parser works record wise. It is not possible to go back, once a record has been parsed from the input stream. + +

    Creating instances

    +

    + There are several static factory methods that can be used to create instances for various types of resources: +

    + +

    + Alternatively parsers can also be created by passing a Reader directly to the sole constructor. + + For those who like fluent APIs, parsers can be created using CSVFormat.parse(java.io.Reader) as a shortcut: +

    +
    + for(CSVRecord record : CSVFormat.EXCEL.parse(in)) {
    +     ...
    + }
    + 
    + +

    Parsing record wise

    +

    + To parse a CSV input from a file, you write: +

    + +
    + File csvData = new File("/path/to/csv");
    + CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180);
    + for (CSVRecord csvRecord : parser) {
    +     ...
    + }
    + 
    + +

    + This will read the parse the contents of the file using the + RFC 4180 format. +

    + +

    + To parse CSV input in a format like Excel, you write: +

    + +
    + CSVParser parser = CSVParser.parse(csvData, CSVFormat.EXCEL);
    + for (CSVRecord csvRecord : parser) {
    +     ...
    + }
    + 
    + +

    + If the predefined formats don't match the format at hands, custom formats can be defined. More information about + customising CSVFormats is available in CSVFormat JavaDoc. +

    + +

    Parsing into memory

    +

    + If parsing record wise is not desired, the contents of the input can be read completely into memory. +

    + +
    + Reader in = new StringReader("a;b\nc;d");
    + CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
    + List<CSVRecord> list = parser.getRecords();
    + 
    + +

    + There are two constraints that have to be kept in mind: +

    + +
      +
    1. Parsing into memory starts at the current position of the parser. If you have already parsed records from + the input, those records will not end up in the in memory representation of your CSV data.
    2. +
    3. Parsing into memory may consume a lot of system resources depending on the input. For example if you're + parsing a 150MB file of CSV data the contents will be read completely into memory.
    4. +
    + +

    Notes

    +

    + Internal parser state is completely covered by the format and the reader-state. +

    +
    Version:
    +
    $Id: CSVParser.java 1743529 2016-05-12 17:02:05Z ggregory $
    +
    See Also:
    package documentation for more details
    +
  • +
+
+
+ +
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        CSVParser

        +
        public CSVParser(Reader reader,
        +         CSVFormat format)
        +          throws IOException
        +
        Customized 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. +

        +
        Parameters:
        reader - a Reader containing CSV-formatted input. Must not be null.
        format - the CSVFormat used for CSV parsing. Must not be null.
        +
        Throws:
        +
        IllegalArgumentException - If the parameters of the format are inconsistent or if either reader or format are null.
        +
        IOException - If there is a problem reading the header or skipping the first record
        +
      • +
      + + + +
        +
      • +

        CSVParser

        +
        public CSVParser(Reader reader,
        +         CSVFormat format,
        +         long characterOffset,
        +         long recordNumber)
        +          throws IOException
        +
        Customized 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. +

        +
        Parameters:
        reader - a Reader containing CSV-formatted input. Must not be null.
        format - the CSVFormat used for CSV parsing. Must not be null.
        characterOffset - Lexer offset when the parser does not start parsing at the beginning of the source.
        recordNumber - The next record number to assign
        +
        Throws:
        +
        IllegalArgumentException - If the parameters of the format are inconsistent or if either reader or format are null.
        +
        IOException - If there is a problem reading the header or skipping the first record
        Since:
        +
        1.1
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        parse

        +
        public static CSVParser parse(File file,
        +              Charset charset,
        +              CSVFormat format)
        +                       throws IOException
        +
        Creates a parser for the given File. + +

        Note: This method internally creates a FileReader using + FileReader.FileReader(java.io.File) which in turn relies on the default encoding of the JVM that + is executing the code. If this is insufficient create a URL to the file and use + parse(URL, Charset, CSVFormat)

        +
        Parameters:
        file - a CSV file. Must not be null.
        charset - A charset
        format - the CSVFormat used for CSV parsing. Must not be null.
        +
        Returns:
        a new parser
        +
        Throws:
        +
        IllegalArgumentException - If the parameters of the format are inconsistent or if either file or format are null.
        +
        IOException - If an I/O error occurs
        +
      • +
      + + + +
        +
      • +

        parse

        +
        public static CSVParser parse(String string,
        +              CSVFormat format)
        +                       throws IOException
        +
        Creates a parser for the given String.
        +
        Parameters:
        string - a CSV string. Must not be null.
        format - the CSVFormat used for CSV parsing. Must not be null.
        +
        Returns:
        a new parser
        +
        Throws:
        +
        IllegalArgumentException - If the parameters of the format are inconsistent or if either string or format are null.
        +
        IOException - If an I/O error occurs
        +
      • +
      + + + +
        +
      • +

        parse

        +
        public static CSVParser parse(URL url,
        +              Charset charset,
        +              CSVFormat format)
        +                       throws IOException
        +
        Creates a parser for the given URL. + +

        + If you do not read all records from the given url, you should call close() on the parser, unless + you close the url. +

        +
        Parameters:
        url - a URL. Must not be null.
        charset - the charset for the resource. Must not be null.
        format - the CSVFormat used for CSV parsing. Must not be null.
        +
        Returns:
        a new parser
        +
        Throws:
        +
        IllegalArgumentException - If the parameters of the format are inconsistent or if either url, charset or format are null.
        +
        IOException - If an I/O error occurs
        +
      • +
      + + + + + + + +
        +
      • +

        getCurrentLineNumber

        +
        public long getCurrentLineNumber()
        +
        Returns the current line number in the input stream. + +

        + ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to + the record number. +

        +
        Returns:
        current line number
        +
      • +
      + + + +
        +
      • +

        getHeaderMap

        +
        public Map<String,IntegergetHeaderMap()
        +
        Returns a copy of the header map that iterates in column order. +

        + The map keys are column names. The map values are 0-based indices. +

        +
        Returns:
        a copy of the header map that iterates in column order.
        +
      • +
      + + + +
        +
      • +

        getRecordNumber

        +
        public long getRecordNumber()
        +
        Returns the current record number in the input stream. + +

        + ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to + the line number. +

        +
        Returns:
        current record number
        +
      • +
      + + + +
        +
      • +

        getRecords

        +
        public List<CSVRecordgetRecords()
        +                           throws IOException
        +
        Parses the CSV input according to the given format and returns the content as a list of + CSVRecords. + +

        + The returned content starts at the current parse-position in the stream. +

        +
        Returns:
        list of CSVRecords, may be empty
        +
        Throws:
        +
        IOException - on parse error or input read-failure
        +
      • +
      + + + +
        +
      • +

        isClosed

        +
        public boolean isClosed()
        +
        Gets whether this parser is closed.
        +
        Returns:
        whether this parser is closed.
        +
      • +
      + + + +
        +
      • +

        iterator

        +
        public Iterator<CSVRecorditerator()
        +
        Returns an iterator on the records. + +

        IOExceptions occurring during the iteration are wrapped in a + RuntimeException. + If the parser is closed a call to next() will throw a + NoSuchElementException.

        +
        +
        Specified by:
        +
        iterator in interface Iterable<CSVRecord>
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + +

Copyright © 2016 The Apache Software Foundation. All rights reserved.

+ \ No newline at end of file