Oracle Fusion Middleware extensions for Applications Core API Reference
11g Release 7 (11.1.7)

E22562-07

oracle.apps.fnd.applcore.attachments.utility
Class CsvTokenizer

java.lang.Object
  extended by oracle.apps.fnd.applcore.attachments.utility.CsvTokenizer
All Implemented Interfaces:
java.util.Enumeration

public class CsvTokenizer
extends java.lang.Object
implements java.util.Enumeration

This class parses strings for CSV (Comma Seperated Variable) data. I define this format to be (and this should be consistant with all databases and spreadsheets): 1. fields seperated by commas. 2. a field will be null if two commas are adjacent. 3. fields have leading and terminating space chars trimmed. 4. If a field contains a comma it must be quoted. The quote char is ' (single quote). 5. A field is determined to be quoted if is starts with the quote char. 6. If a quoted field contains a quote, it must be escaped. The escape character (perversely) is a single quote. Note that surrounding quotes and escaped quotes are not taken out of the fields. It is assumed that the calling program will do this. eg: a,b,c ==> fields a b and c eg: 'a',,c ==> fields 'a' null and c eg: , ==> fields null and null eg: 'a,b',c ==> fields 'a,b' and c eg: 'a''b',c ==> fields 'a''b' and c This class works in much the same way as java.util.StringTokenizer. Standard Usage: String imp = "a,b,c"; CSVTokenizer tokenizer = new CSVTokenizer(inp); while (tokenizer.hasMoreTokens()) { System.out.println("==>" + tokenizer.nextToken() + "<=="); }

David Groves

Field Summary
static java.lang.String COMMA
           
 
Constructor Summary
CsvTokenizer(java.lang.String value)
          Constructs a CSV tokenizer for the specified string.
 
Method Summary
 boolean hasMoreElements()
          Returns the same value as the hasMoreTokens method.
 boolean hasMoreTokens()
          Tests if there are more tokens available from this tokenizer's string.
 java.lang.Object nextElement()
          Returns the next token from this string tokenizer.
 java.lang.Object nextToken()
          Returns the same value as the nextElement method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMA

public static final java.lang.String COMMA
See Also:
Constant Field Values
Constructor Detail

CsvTokenizer

public CsvTokenizer(java.lang.String value)
Constructs a CSV tokenizer for the specified string. The delimiter for seperating tokens is implicitly the comma ',' character.

Parameters:
value - The string tokenize.
Method Detail

hasMoreTokens

public boolean hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string. If this method returns true, then a subsequent call to nextToken with no argument will successfully return a token.

Returns:
true if there are more tokens that may be fetched (using nextToken()), false otherwise.

hasMoreElements

public boolean hasMoreElements()
Returns the same value as the hasMoreTokens method.

Specified by:
hasMoreElements in interface java.util.Enumeration

nextToken

public java.lang.Object nextToken()
                           throws java.util.NoSuchElementException
Returns the same value as the nextElement method.

Throws:
java.util.NoSuchElementException

nextElement

public java.lang.Object nextElement()
                             throws java.util.NoSuchElementException
Returns the next token from this string tokenizer.

Specified by:
nextElement in interface java.util.Enumeration
Returns:
the next token from this string tokenizer (always a String).
Throws:
java.lang.Exception - if there is a problem parsing the string (ie it is not a valid CSV file).
java.util.NoSuchElementException

Oracle Fusion Middleware extensions for Applications Core API Reference
11g Release 7 (11.1.7)

E22562-07

Copyright © 2013 Oracle. All Rights Reserved.