Overview
CsvUtils is a utility class that provides helper methods for parsing CSV and tab-delimited data, as well as safe string-to-integer conversion. This class is commonly used in Mapper classes to parse input data fields.
Package: circlenet.common
Source: /workspace/source/src/main/java/circlenet/common/CsvUtils.java:3
Methods
split()
Splits a CSV line into an array of string fields.The CSV line to split
String[] - Array of field values (empty strings for empty fields)
Implementation: Uses String.split(",", -1) to preserve empty trailing fields.
Example Usage
TaskBSimple.java:29 - parsing activity log entries.
splitTab()
Splits a tab-delimited line into an array of string fields.The tab-delimited line to split
String[] - Array of field values (empty strings for empty fields)
Implementation: Uses String.split("\\t", -1) to preserve empty trailing fields.
Example Usage
TaskBSimple.java:72 - parsing intermediate MapReduce output (tab-separated key-value pairs).
toInt()
Safely converts a string to an integer with a fallback value on parse failure.The string value to parse
The default value to return if parsing fails
int - Parsed integer value, or fallback if parsing fails
Error Handling: Catches all exceptions during parsing and returns the fallback value. Automatically trims whitespace before parsing.
Example Usage
TaskBSimple.java:95 - safely parsing count values during join operation.
Usage Patterns
Parsing CSV Input Data
Parsing MapReduce Intermediate Output
MapReduce jobs output tab-separated key-value pairs by default:Combining Split and ToInt
TaskBSimple.java:119 - parsing and ranking top results.
Design Notes
- Utility Class: Constructor is private; all methods are static
- Preserve Empty Fields: Both split methods use
-1limit to preserve trailing empty fields - Null Safety:
toInt()handles any exception (null, empty, invalid format) with fallback - Performance: Simple delegation to Java standard library methods for efficiency