Java tutorial
/** * PureInfo Quake * @(#)CSVObjectsImpl.java 1.0 Jul 27, 2006 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.xls2srm; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.apache.commons.lang.StringUtils; import com.pureinfo.dolphin.model.DolphinObject; import com.pureinfo.dolphin.model.DolphinObjects; import com.pureinfo.dolphin.model.IObjects; import com.pureinfo.dolphin.persister.ISession; import com.pureinfo.force.container.Pager; import com.pureinfo.force.exception.PureException; public class CSVObjectsImpl implements IObjects { private List m_datas = null; private Iterator m_iter = null; public CSVObjectsImpl(String _sFileName) throws PureException { m_datas = new ArrayList(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(_sFileName))); String sLine = null; while ((sLine = br.readLine()) != null) { String[] fields = StringUtils.splitPreserveAllTokens(sLine, ','); DolphinObject obj = new DolphinObject(); for (int i = 0; i < fields.length; i++) { obj.setProperty(String.valueOf(i), fields[i]); } m_datas.add(obj); } } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } public Class getElementClass() { throw new UnsupportedOperationException(); } public void setSize(int _nSize) { throw new UnsupportedOperationException(); } public int getSize() { return m_datas.size(); } public boolean isEmpty() { return m_datas.size() == 0; } public DolphinObjects open(Class _elementClass, PreparedStatement _preparedStatement, ISession _session) throws PureException { throw new UnsupportedOperationException(); } public DolphinObjects open(Class _elementClass, ResultSet _rsData, ISession _session) throws PureException { throw new UnsupportedOperationException(); } public DolphinObject next() throws PureException { if (m_iter == null) m_iter = m_datas.iterator(); if (m_iter.hasNext()) { return (DolphinObject) m_iter.next(); } else { return null; } } public void skip(int _nTotal) throws PureException { for (int i = 0; i < _nTotal && m_iter.hasNext(); i++) { m_iter.next(); } } public List toList() throws PureException { return Collections.unmodifiableList(m_datas); } public List toList(Pager _pager) throws PureException { throw new UnsupportedOperationException(); } public void addTo(Collection _collection) throws PureException { throw new UnsupportedOperationException(); } public void removeFrom(Collection _collection) throws PureException { throw new UnsupportedOperationException(); } public Iterator iterator() { return m_datas.iterator(); } public void clear() { m_datas.clear(); m_iter = null; } }