Package batch.internal.support

Source Code of batch.internal.support.ResourceFieldSetReader

package batch.internal.support;

import java.io.IOException;

import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

import batch.internal.FieldSet;
import batch.internal.InputSource;

/**
*/
public class ResourceFieldSetReader implements InputSource<FieldSet> {

  private final ResourceLineReader lineReader;

  private final DelimitedLineTokenizer tokenizer;

  public ResourceFieldSetReader(Resource resource, char delimiter) throws IOException {
    super();
    Assert.notNull(resource, "'resource' cannot be null.");
    this.lineReader = new ResourceLineReader(resource);
    this.tokenizer = new DelimitedLineTokenizer(delimiter);
  }

  public ResourceFieldSetReader(Resource resource) throws IOException {
    this(resource, DelimitedLineTokenizer.DELIMITER_COMMA);
  }

  public FieldSet read() {
    String line = (String) lineReader.read();
    if (line == null) {
      return null;
    }
    String[] result = tokenizer.tokenize(line);
    for (int i = 0; i < result.length; i++) {
      result[i] = result[i].trim();
    }
    return new FieldSet(result);
  }
}
TOP

Related Classes of batch.internal.support.ResourceFieldSetReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.