本文整理汇总了Java中com.fasterxml.jackson.dataformat.csv.CsvMapper.enable方法的典型用法代码示例。如果您正苦于以下问题:Java CsvMapper.enable方法的具体用法?Java CsvMapper.enable怎么用?Java CsvMapper.enable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.dataformat.csv.CsvMapper
的用法示例。
在下文中一共展示了CsvMapper.enable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRunSorterFirstColumn
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterFirstColumn() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).build();
verifyCSV(testInput1, 1, 2, 4, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput1, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0), true);
}
verifyCSV(testOutput, 1, 2, 4, mapper, schema);
}
示例2: testRunSorterSecondColumn
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterSecondColumn() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).build();
verifyCSV(testInput1, 1, 2, 4, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput1, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(1), true);
}
verifyCSV(testOutput, 1, 2, 4, mapper, schema);
}
示例3: testRunSorterSecondColumnThenFirst
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterSecondColumnThenFirst() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).build();
verifyCSV(testInput3, 1, 2, 5, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput3, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(1, 0), true);
}
verifyCSV(testOutput, 1, 2, 5, mapper, schema);
}
示例4: testRunSorterFirstColumnThenSecond
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterFirstColumnThenSecond() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).build();
verifyCSV(testInput3, 1, 2, 5, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput3, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0, 1), true);
}
verifyCSV(testOutput, 1, 2, 5, mapper, schema);
}
示例5: testRunSorterTSV
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterTSV() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).setColumnSeparator('\t').build();
verifyCSV(testInput4, 1, 2, 5, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput4, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 1, schema, CSVSorter.getComparator(0, 1), true);
}
verifyCSV(testOutput, 1, 2, 5, mapper, schema);
}
示例6: testRunSorterTSVMultipleHeaderLines
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Test
public final void testRunSorterTSVMultipleHeaderLines() throws Exception {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
// csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
// mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
CsvSchema schema = CsvSchema.builder().setUseHeader(false).setColumnSeparator('\t').build();
verifyCSV(testInput5, 10, 2, 5, mapper, schema);
try (Reader inputReader = Files.newBufferedReader(testInput5, StandardCharsets.UTF_8)) {
CSVSorter.runSorter(inputReader, testOutput, 10, schema, CSVSorter.getComparator(0, 1), true);
}
verifyCSV(testOutput, 10, 2, 5, mapper, schema);
}
示例7: loadPublisherMap
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
private ImmutableMultimap<String, String> loadPublisherMap(String file) {
// todo make sortedsetmultimap
Multimap<String, String> temp = LinkedHashMultimap.create();
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
try {
MappingIterator<Object[]> it = mapper.reader(Object[].class).readValues(
getClass().getResourceAsStream(file));
while (it.hasNext()) {
Object[] row = it.next();
if (row.length > 1 && (row[0] != null && row[1] != null)
&& (!row[0].toString().isEmpty() && !row[1].toString().isEmpty())) {
temp.put(row[1].toString().trim(), row[0].toString().trim());
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return ImmutableMultimap.copyOf(temp);
}
示例8: test
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public void test() throws IOException {
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
CsvSchema schema = CsvSchema.emptySchema();
// schema = schema.withHeader();
// schema = schema.withQuoteChar('\'');
// File csvFile = new File("/Temp/llunatic/doctors/10k/doctor.csv");
File csvFile = new File("/Users/donatello/Temp/chaseBench-workspace/LUBM/data/01k/src-emailAddress.csv");
long start = new Date().getTime();
MappingIterator<String[]> it = mapper.readerFor(String[].class).with(schema).readValues(csvFile);
String[] row = it.next();
System.out.println(Arrays.asList(row));
long end = new Date().getTime();
System.out.println("**** " + (end - start) + " ms");
// while (it.hasNext()) {
// String[] row = it.next();
// System.out.println(Arrays.asList(row));
// }
}
示例9: main
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static void main (String [] args) throws IOException{
System.out.println("Reading Datasets and Categories...");
URL file = Resources.getResource("datasetsAndCategories.tsv");
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
File csvFile = new File(file.getFile());
CsvSchema schema = CsvSchema.emptySchema().withColumnSeparator('\t');
MappingIterator<String[]> it = mapper.reader(String[].class).with(schema).readValues(csvFile);
while (it.hasNext()){
String[] arr = it.next();
m.add(m.createStatement(m.createResource(arr[0]), m.createProperty(":hasDomain"), m.createTypedLiteral(arr[1])));
m.add(m.createStatement(m.createResource(arr[0]), m.createProperty(":getFromLOV"), m.createTypedLiteral(true)));
}
System.out.println("Writing dump...");
File f = new File("categories.ttl");
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
m.write(fos, "TURTLE");
}
示例10: writeCsvFile
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
/**
* Write a new inventory report to S3 and returns a locator which includes this inventory report's information
* @return Locator which includes the information of this new report
* @throws IOException thrown when GZIPOutputStream not created successfully or csvMapper.write() fails
*/
public InventoryManifest.Locator writeCsvFile(List<InventoryReportLine> inventoryReportLine) throws IOException{
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(JsonGenerator.Feature.IGNORE_UNKNOWN);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
csvMapper.writer(schema).writeValues(gzipOutputStream).writeAll(inventoryReportLine).close();
byte[] zipByteArray = byteArrayOutputStream.toByteArray();
InputStream zipInputStream = new ByteArrayInputStream(zipByteArray);
ObjectMetadata metaData = new ObjectMetadata();
metaData.setContentLength(zipByteArray.length);
PutObjectRequest request = new PutObjectRequest(bucketName, outputInventoryReportKey, zipInputStream, metaData);
s3Client.putObject(request);
return this.buildLocator(zipByteArray);
}
示例11: getSafeSortingMapper
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static CsvMapper getSafeSortingMapper() {
CsvFactory csvFactory = new CsvFactory();
csvFactory.enable(CsvParser.Feature.TRIM_SPACES);
csvFactory.enable(CsvParser.Feature.WRAP_AS_ARRAY);
csvFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
CsvMapper mapper = new CsvMapper(csvFactory);
mapper.enable(CsvParser.Feature.TRIM_SPACES);
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
mapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
// true);
return mapper;
}
示例12: generateCsvReport
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public void generateCsvReport(List<ZeroCodeCsvReport> zeroCodeCsvReportRows) {
/*
* Write to a CSV file
*/
CsvSchema schema = CsvSchema.builder()
.setUseHeader(true)
.addColumn("scenarioName")
.addColumn("scenarioLoop", CsvSchema.ColumnType.NUMBER)
.addColumn("stepName")
.addColumn("stepLoop", CsvSchema.ColumnType.NUMBER)
.addColumn("correlationId")
.addColumn("requestTimeStamp")
.addColumn("responseTimeStamp")
.addColumn("responseDelayMilliSec", CsvSchema.ColumnType.NUMBER)
.addColumn("result")
.build();
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
ObjectWriter writer = csvMapper.writer(schema.withLineSeparator("\n"));
try {
writer.writeValue(
new File(TARGET_FULL_REPORT_DIR +
TARGET_FULL_REPORT_CSV_FILE_NAME +
"_" +
LocalDateTime.now().toString().replace(":", "-") +
".csv"),
zeroCodeCsvReportRows);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Exception while Writing full CSV report. Details: " + e);
}
}
示例13: main
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
public static void main(String[] args) {
List<User> users = new ArrayList<>();
User userHeader = new User("First", "Last", "Age");
User user1 = new User("First name1", "Last Name1", null);
User user2 = new User("First name2", "Last Name2", "22");
users.add(userHeader);
users.add(user1);
users.add(user2);
CsvSchema schema = CsvSchema.builder()
.addColumn("firstName")
.addColumn("lastName")
.addColumn("age", CsvSchema.ColumnType.NUMBER)
//.addColumn("comments")
//.setUseHeader(true)
//.setStrictHeaders(false)
.build();
// CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
// ObjectMapper mapper = new CsvMapper();
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
ObjectWriter writer = mapper.writer(schema.withLineSeparator("\n"));
try {
writer.writeValue(new File("target/ModifiedUsers.csv"), users);
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: parseRows
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Override
public List<String[]> parseRows(final Reader input) throws Exception {
CsvMapper csvMapper = new CsvMapper();
csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
MappingIterator<String[]> iterator = csvMapper.reader(String[].class).readValues(input);
List<String[]> values = new ArrayList<String[]>();
while (iterator.hasNext()) {
values.add(iterator.next());
}
return values;
}
示例15: get
import com.fasterxml.jackson.dataformat.csv.CsvMapper; //导入方法依赖的package包/类
@Override
public List<FlatVotes> get() {
Map<FlatVotes, FlatVotes> voteMap = new HashMap<>();
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
try {
VoteTitleParser p = new VoteTitleParser();
MappingIterator<Object[]> it = mapper.readerFor(Object[].class).readValues(in);
it.next();
it.next();
while (it.hasNext()) {
Object[] value = it.next();
List<Talk> selectedTalks = new ArrayList<>();
for (int i = 7; i < value.length; i++) {
Object o = value[i];
if (!(o instanceof String)) {
continue;
}
String s = (String) o;
if (s.isEmpty()) {
continue;
}
Talk talk = p.parse(s);
selectedTalks.add(talk);
}
FlatVotes key = new FlatVotes(selectedTalks);
if (voteMap.containsKey(key)) {
key = voteMap.get(key);
key.setCount(key.getCount() + 1);
} else {
voteMap.put(key, key);
}
}
} catch (IOException e) {
throw new IllegalStateException("Unable to parse " + in);
}
List<FlatVotes> votes = voteMap.keySet().stream()
.sorted()
.collect(Collectors.toList());
// List<FlatVotes> votes = new ArrayList<>();
// try (InputStream is = in;
// BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
// br.readLine(); // ignore header
//
// String line;
// line = br.readLine();
// line = br.readLine();
// Pattern topic = Pattern.compile("(?:\"[^\"]+\"|[^,]+)");
// Pattern speakerTitle = Pattern.compile("([^—-]*) [—-] (.*)");
// while ((line = br.readLine()) != null) {
// Matcher matcher = topic.matcher(line);
// List<Talk> selectedTalks = new ArrayList<>();
// while (matcher.find()) {
// String topicLine = matcher.group();
// if (topicLine.charAt(0) == '"') {
// topicLine = topicLine.substring(1, topicLine.length() - 1);
// }
// Talk parsed = p.parse(topicLine);
// selectedTalks.add(parsed);
// }
// votes.add(new FlatVotes(selectedTalks));
// }
//
// } catch (IOException e) {
// e.printStackTrace();
// }
return votes;
}