本文整理汇总了Java中com.csvreader.CsvWriter.setUseTextQualifier方法的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter.setUseTextQualifier方法的具体用法?Java CsvWriter.setUseTextQualifier怎么用?Java CsvWriter.setUseTextQualifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.setUseTextQualifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test57
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test57() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, '\t', Charset
.forName("ISO-8859-1"));
Assert.assertTrue(writer.getUseTextQualifier());
writer.setUseTextQualifier(false);
Assert.assertFalse(writer.getUseTextQualifier());
writer.write("1,2");
writer.write("3");
writer.write("blah \"some stuff in quotes\"");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("1,2\t3\tblah \"some stuff in quotes\"\r\n", data);
}
示例2: test74
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test74() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
writer.setUseTextQualifier(false);
writer.write("1,2");
writer.write("3");
writer.write("blah \"some stuff in quotes\"");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("1\\,2,3,blah \"some stuff in quotes\"\r\n", data);
}
示例3: test124
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test124() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.setRecordDelimiter(';');
writer.setUseTextQualifier(false);
writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
writer.write("1;2");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("1\\;2;", data);
}
示例4: joinAsCsv
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* Joins the given values as a comma-separated string. Each value will be encoded in this string by escaping any
* commas in the value with a backslash.
*
* @param values the values to join (null is acceptable).
* @return the CSV string consisting of the values. If the values were null, an empty String.
*/
public static String joinAsCsv(String[] values) {
if (values == null) {
return StringUtils.EMPTY;
}
try {
final StringWriter sw = new StringWriter();
final CsvWriter csvWriter = new CsvWriter(sw, ',');
csvWriter.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
csvWriter.setUseTextQualifier(false);
csvWriter.writeRecord(values);
csvWriter.flush();
csvWriter.close();
return sw.toString();
} catch (final IOException e) {
throw new IllegalStateException("Could not encode as CSV record: " + e, e);
}
}
示例5: test123
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test123() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("#123");
writer.endRecord();
writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
writer.setUseTextQualifier(false);
writer.write("#123");
writer.endRecord();
writer.write("#");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("\"#123\"\r\n\\#123\r\n\\#\r\n", data);
}
示例6: test131
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test131() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.setUseTextQualifier(false);
writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
writer.write("1,\\\r\n2");
writer.endRecord();
writer.setRecordDelimiter(';');
writer.write("1,\\;2");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("1\\,\\\\\\\r\\\n2\r\n1\\,\\\\\\;2;", data);
}