• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CSVStrategy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.googlecode.jcsv.CSVStrategy的典型用法代码示例。如果您正苦于以下问题:Java CSVStrategy类的具体用法?Java CSVStrategy怎么用?Java CSVStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CSVStrategy类属于com.googlecode.jcsv包,在下文中一共展示了CSVStrategy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: joinColumns

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Override
   public String joinColumns(String[] data, CSVStrategy strategy) {
final String delimiter = String.valueOf(strategy.getDelimiter());
final String quote = String.valueOf(strategy.getQuoteCharacter());
final String doubleQuote = quote + quote;

// check each column for delimiter or quote characters
// and escape them if neccessary
for (int i = 0; i < data.length; i++) {
    if (data[i].contains(delimiter) || data[i].contains(quote)) {
	if (data[i].contains(quote)) {
	    data[i] = data[i].replaceAll(Pattern.quote(quote), doubleQuote);
	}
	
	data[i] = quote + data[i] + quote;
    }
}

return CSVUtil.implode(data, delimiter);
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:21,代码来源:CSVColumnJoinerImpl.java


示例2: testJoinColumns

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Test
public void testJoinColumns() {
	CSVColumnJoiner columnJoiner = new SimpleCSVColumnJoiner();

	// uses ; as delimiter
	final CSVStrategy strategy = CSVStrategy.DEFAULT;

	String[] data = {"A", "B", "C"};
	String result = columnJoiner.joinColumns(data, strategy);
	String expected = "A;B;C";
	assertEquals(expected, result);

	data = new String[]{"A"};
	result = columnJoiner.joinColumns(data, strategy);
	expected = "A";
	assertEquals(expected, result);

	data = new String[0];
	result = columnJoiner.joinColumns(data, strategy);
	expected = "";
	assertEquals(expected, result);
}
 
开发者ID:trein,项目名称:gtfs-java,代码行数:23,代码来源:SimplCSVColumnJoinerTest.java


示例3: read

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public CoolRecord[] read() throws Exception {

		ArrayList<CoolRecord> records = new ArrayList<CoolRecord>();
		Reader reader = new FileReader(csvFileURI);
		CSVReader<String[]> csvReader = new CSVReaderBuilder<String[]>(reader)
				.entryParser(new DefaultCSVEntryParser())
				.strategy(CSVStrategy.UK_DEFAULT).build();

		boolean hasColumnRowSkipped = false;
		for (String[] csvReaderRecord : csvReader.readAll()) {

			if (!hasColumnRowSkipped) {
				hasColumnRowSkipped = true;
				continue;
			}

			CoolRecord record = null;

			// Column Detail is not provided by user. So, default is set to
			// String for all columns
			if (columns == null || columns.length < 0) {

				columns = new CoolColumn[csvReaderRecord.length];
				for (int i = 0; i < columns.length; i++) {
					columns[i] = new CoolColumn(null, i, String.class);
				}
			}
			record = new CoolRecord(columns, csvReaderRecord);

			records.add(record);
		}

		return records.toArray(new CoolRecord[records.size()]);
	}
 
开发者ID:realsoelynn,项目名称:CoolReader,代码行数:35,代码来源:CSVDataSource.java


示例4: exportCSV

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public static <T> void exportCSV(String fileName, CSVEntryConverter<T> headerConverter,
                                 CSVEntryConverter<T> contentConverter, T emptyItem,
                                 List<T> list, Stage stage) {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialFileName(fileName);
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {
        try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file, false), Charsets.UTF_8)) {
            CSVWriter<T> headerWriter = new CSVWriterBuilder<T>(outputStreamWriter)
                    .strategy(CSVStrategy.UK_DEFAULT)
                    .entryConverter(headerConverter)
                    .build();
            headerWriter.write(emptyItem);

            CSVWriter<T> contentWriter = new CSVWriterBuilder<T>(outputStreamWriter)
                    .strategy(CSVStrategy.UK_DEFAULT)
                    .entryConverter(contentConverter)
                    .build();
            contentWriter.writeAll(list);
        } catch (RuntimeException | IOException e) {
            e.printStackTrace();
            log.error(e.getMessage());
            new Popup<>().error(Res.get("guiUtil.accountExport.exportFailed", e.getMessage()));
        }
    }
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:28,代码来源:GUIUtil.java


示例5: tokenizeLine

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
/**
    * Performs a split() on the input string. Uses the delimiter specified in the csv strategy.
    */
   @Override
   public List<String> tokenizeLine(String line, CSVStrategy strategy, BufferedReader reader) throws IOException {
if (line.equals("")) {
    return new ArrayList<String>();
}

// split the line and preserve all tokens
List<String> tokens = Arrays.asList(CSVUtil.split(line, strategy.getDelimiter(), true));

return tokens;
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:15,代码来源:SimpleCSVTokenizer.java


示例6: testJoinColumns

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Test
public void testJoinColumns() {
	CSVColumnJoiner columnJoiner = new CSVColumnJoinerImpl();

	// uses ; as delimiter
	final CSVStrategy strategy = CSVStrategy.DEFAULT;

	// simple test cases
	String[] data = {"A", "B", "C"};
	String result = columnJoiner.joinColumns(data, strategy);
	String expected = "A;B;C";
	assertEquals(expected, result);

	// single token test
	data = new String[]{"A"};
	result = columnJoiner.joinColumns(data, strategy);
	expected = "A";
	assertEquals(expected, result);

	// empty array test
	data = new String[0];
	result = columnJoiner.joinColumns(data, strategy);
	expected = "";
	assertEquals(expected, result);

	// more complex test cases
	// delimiter in token test case
	data = new String[]{"A", "B", "C;D"};
	result = columnJoiner.joinColumns(data, strategy);
	expected = "A;B;\"C;D\"";
	assertEquals(expected, result);

	// quote in token
	data = new String[]{"A", "B", "C\";\"D"};
	result = columnJoiner.joinColumns(data, strategy);
	expected = "A;B;\"C\"\";\"\"D\"";
	assertEquals(expected, result);
}
 
开发者ID:trein,项目名称:gtfs-java,代码行数:39,代码来源:CSVColumnJoinerImplTest.java


示例7: setUp

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Before
   public void setUp() throws Exception {
Reader reader = new InputStreamReader(this.getClass().getResourceAsStream("/persons.csv"));
CSVStrategy strategy = new CSVStrategy(';', '"', '#', true, true);
CSVReader<Person> csvReader = new CSVReaderBuilder<Person>(reader).entryParser(new PersonEntryParser())
        .strategy(strategy).build();
this.cachedReader = new CachedCSVReaderImpl<Person>(csvReader);
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:9,代码来源:CachedCSVReaderImplTest.java


示例8: WynikCsvDtoReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public WynikCsvDtoReader(CSVStrategy csvStrategy) {
    super(csvStrategy);
}
 
开发者ID:OtwartaPlatformaWyborcza,项目名称:OPW-backend-JavaEE,代码行数:4,代码来源:WynikCsvDtoReader.java


示例9: OkregowaCsvDtoReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public OkregowaCsvDtoReader(CSVStrategy csvStrategy) {
    super(csvStrategy);
}
 
开发者ID:OtwartaPlatformaWyborcza,项目名称:OPW-backend-JavaEE,代码行数:4,代码来源:OkregowaCsvDtoReader.java


示例10: AbstractCSVReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
/**
 * @param csvStrategy {@link https://code.google.com/p/jcsv/wiki/CSVStrategy}
 */
public AbstractCSVReader(CSVStrategy csvStrategy) {
    this.csvStrategy = csvStrategy;
}
 
开发者ID:OtwartaPlatformaWyborcza,项目名称:OPW-backend-JavaEE,代码行数:7,代码来源:AbstractCSVReader.java


示例11: UserCsvDtoReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public UserCsvDtoReader(CSVStrategy csvStrategy) {
    super(csvStrategy);
}
 
开发者ID:OtwartaPlatformaWyborcza,项目名称:OPW-backend-JavaEE,代码行数:4,代码来源:UserCsvDtoReader.java


示例12: ObwodowaCsvDtoReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
public ObwodowaCsvDtoReader(CSVStrategy csvStrategy) {
    super(csvStrategy);
}
 
开发者ID:OtwartaPlatformaWyborcza,项目名称:OPW-backend-JavaEE,代码行数:4,代码来源:ObwodowaCsvDtoReader.java


示例13: createCSVReader

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private CSVReader<TweetToSchedule> createCSVReader(Reader reader) {
       return (CSVReader<TweetToSchedule>) new CSVReaderBuilder(reader)
               .strategy(CSVStrategy.UK_DEFAULT)
               .entryParser(new TweetToScheduleEntryParser()).build();
   }
 
开发者ID:jstanier,项目名称:tweet-scheduler,代码行数:7,代码来源:InputParser.java


示例14: loadSeries

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Override
protected List<SeriesValue> loadSeries(AbstractBuild build) throws IOException
{
    List<SeriesValue> values = new ArrayList<SeriesValue>();

    FilePath seriesFile = new FilePath(build.getWorkspace(), getFile());

    try
    {
        if (!seriesFile.exists())
        {
            return values;
        }

        CSVReader<String[]> reader = null;

        try
        {
            reader = new CSVReaderBuilder<String[]>(new InputStreamReader(seriesFile.read())).strategy(CSVStrategy.UK_DEFAULT).entryParser(new DefaultCSVEntryParser()).build();

            List<String> headers = reader.readHeader();

            for (String[] row; (row = reader.readNext()) != null;)
            {
                if (row.length == 0 || row[0].isEmpty())
                {
                    continue;
                }

                for (Integer columnIndex = 0; columnIndex < row.length; columnIndex++)
                {
                    String header = headers.get(columnIndex);

                    if (shouldIncludeColumn(header, columnIndex.toString()))
                    {
                        values.add(new SeriesValue(row[columnIndex], header, build));
                    }
                }

                break;
            }
        }
        finally
        {
            if (reader != null)
            {
                reader.close();
            }
        }

        return values;
    }
    catch (InterruptedException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:andrey-vorobiev,项目名称:hudson-graph-plugin,代码行数:58,代码来源:CSVSeries.java


示例15: joinColumns

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
/**
    * Performs a CSVUtil.implode() to concat the columns, it uses the delimiter specified by the
    * csv strategy.
    */
   @Override
   public String joinColumns(String[] data, CSVStrategy strategy) {
return CSVUtil.implode(data, String.valueOf(strategy.getDelimiter()));
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:9,代码来源:SimpleCSVColumnJoiner.java


示例16: tokenizeLine

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Override
   public List<String> tokenizeLine(String line, CSVStrategy strategy, BufferedReader reader) throws IOException {
final char DELIMITER = strategy.getDelimiter();
final char QUOTE = strategy.getQuoteCharacter();
final char NEW_LINE = '\n';

final StringBuilder sb = new StringBuilder(30);
final List<String> token = new ArrayList<String>();

line += NEW_LINE;
State state = State.NORMAL;

int pointer = 0;
while (true) {
    final char c = line.charAt(pointer);
    
    switch (state) {
	case NORMAL:
	    if (c == DELIMITER) {
		token.add(sb.toString());
		sb.delete(0, sb.length());
	    } else if (c == NEW_LINE) {
		if (!((token.size() == 0) && (sb.length() == 0))) {
		    token.add(sb.toString());
		}
		return token;
	    } else if (c == QUOTE) {
		if (sb.length() == 0) {
		    state = State.QUOTED;
		} else if ((line.charAt(pointer + 1) == QUOTE) && (sb.length() > 0)) {
		    sb.append(c);
		    pointer++;
		} else if (line.charAt(pointer + 1) != QUOTE) {
		    state = State.QUOTED;
		}
	    } else {
		sb.append(c);
	    }
	    break;
	
	case QUOTED:
	    if (c == NEW_LINE) {
		sb.append(NEW_LINE);
		pointer = -1;
		line = reader.readLine();
		if (line == null) {
		    throw new IllegalStateException("unexpected end of file, unclosed quotation");
		}
		line += NEW_LINE;
	    } else if (c == QUOTE) {
		if (line.charAt(pointer + 1) == QUOTE) {
		    sb.append(c);
		    pointer++;
		    break;
		} else {
		    state = State.NORMAL;
		}
	    } else {
		sb.append(c);
	    }
	    break;
    }
    
    pointer++;
}
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:67,代码来源:CSVTokenizerImpl.java


示例17: setUp

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Before
   public void setUp() throws Exception {
Reader reader = new InputStreamReader(this.getClass().getResourceAsStream("/persons_quotes.csv"));
CSVStrategy strategy = new CSVStrategy(';', '"', '#', true, true);
this.csvReader = new CSVReaderBuilder<Person>(reader).entryParser(new PersonEntryParser()).strategy(strategy).build();
   }
 
开发者ID:trein,项目名称:gtfs-java,代码行数:7,代码来源:CSVReaderImplTest.java


示例18: testTokenizeLine

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void testTokenizeLine() throws IOException {
	CSVTokenizer tokenizer = new SimpleCSVTokenizer();

	// uses ; as delimiter
	final CSVStrategy strategy = CSVStrategy.DEFAULT;
	final String delimiter = String.valueOf(strategy.getDelimiter());

	// we only do simple tests
	String line = "A;B;C";
	List<String> token = tokenizer.tokenizeLine(line, strategy, null);
	List<String> expected = new ArrayList<String>() {{
		add("A"); add("B"); add("C");
	}};
	assertEquals(expected, token);

	line = "A";
	token = tokenizer.tokenizeLine(line, strategy, null);
	expected = new ArrayList<String>() {{
		add("A");
	}};
	assertEquals(expected, token);

	line = "A;";
	token = tokenizer.tokenizeLine(line, strategy, null);
	expected = new ArrayList<String>() {{
		add("A"); add("");
	}};
	assertEquals(expected, token);

	line = delimiter + delimiter;
	token = tokenizer.tokenizeLine(line, strategy, null);
	expected = new ArrayList<String>() {{
		add(""); add(""); add("");
	}};
	assertEquals(expected, token);

	line = "";
	token = tokenizer.tokenizeLine(line, strategy, null);
	expected = new ArrayList<String>();
	assertEquals(expected, token);
}
 
开发者ID:trein,项目名称:gtfs-java,代码行数:44,代码来源:SimpleCSVTokenizerTest.java


示例19: createStrategyWithDelimiter

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
/**
 *
 * @param delimiter
 * @return a strategy for writing the CSV using the delimiter provided
 */
private CSVStrategy createStrategyWithDelimiter(char delimiter) {
    return new CSVStrategy(delimiter, '"', '#', false, true);
}
 
开发者ID:BingAds,项目名称:BingAds-Java-SDK,代码行数:9,代码来源:SimpleBulkObjectWriter.java


示例20: createStrategyWithDelimiter

import com.googlecode.jcsv.CSVStrategy; //导入依赖的package包/类
/**
 * Create a parsing strategy using the delimiter provided
 *
 * @param delimiter The character used to separate records in the same line
 * @return a csv parsing strategy
 */
private static CSVStrategy createStrategyWithDelimiter(char delimiter) {
    return new CSVStrategy(delimiter, '"', '#', false, true);
}
 
开发者ID:BingAds,项目名称:BingAds-Java-SDK,代码行数:10,代码来源:SimpleBulkObjectReader.java



注:本文中的com.googlecode.jcsv.CSVStrategy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClusteringAgent类代码示例发布时间:2022-05-22
下一篇:
Java AppInfo类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap