本文整理汇总了Java中com.csvreader.CsvWriter类的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter类的具体用法?Java CsvWriter怎么用?Java CsvWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CsvWriter类属于com.csvreader包,在下文中一共展示了CsvWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: test55
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test55() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("");
writer.write("1");
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("\"\",1", data);
}
示例3: test56
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test56() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, '\t', Charset
.forName("ISO-8859-1"));
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\t\"blah \"\"some stuff in quotes\"\"\"\r\n", data);
}
示例4: test58
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test58() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, '\t', Charset
.forName("ISO-8859-1"));
writer.write("data\r\nmore data");
writer.write(" 3\t", false);
writer.write(" 3\t");
writer.write(" 3\t", true);
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("\"data\r\nmore data\"\t3\t3\t\" 3\t\"\r\n", data);
}
示例5: test71
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test71() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.setForceQualifier(true);
writer.write(" data ");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("\"data\"\r\n", data);
}
示例6: test72
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test72() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
Assert.assertEquals('\0', writer.getRecordDelimiter());
writer.setRecordDelimiter(';');
Assert.assertEquals(';', writer.getRecordDelimiter());
writer.write("a;b");
writer.endRecord();
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("\"a;b\";", data);
}
示例7: 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);
}
示例8: test75
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test75() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("1");
writer.endRecord();
writer.writeComment("blah");
writer.write("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\n#blah\r\n2\r\n", data);
}
示例9: test87
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test87() throws Exception {
CsvWriter writer = new CsvWriter("temp.csv");
writer.write("1");
writer.close();
CsvReader reader = new CsvReader("temp.csv");
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("1", reader.get(0));
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertFalse(reader.readRecord());
reader.close();
new File("temp.csv").delete();
}
示例10: test120
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test120() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("1,2");
writer.endRecord();
buffer = stream.toByteArray();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("", data);
writer.flush(); // testing that flush flushed to stream
buffer = stream.toByteArray();
stream.close();
data = Charset.forName("ISO-8859-1").decode(ByteBuffer.wrap(buffer))
.toString();
Assert.assertEquals("\"1,2\"\r\n", data);
writer.close();
}
示例11: test121
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test121() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.writeRecord(new String[] { " 1 ", "2" }, false);
writer.writeRecord(new String[] { " 1 ", "2" });
writer.writeRecord(new String[] { " 1 ", "2" }, true);
writer.writeRecord(new String[0], true);
writer.writeRecord(null, true);
writer.close();
buffer = stream.toByteArray();
stream.close();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("1,2\r\n1,2\r\n\" 1 \",2\r\n", data);
}
示例12: test122
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test122() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("1,2");
writer.write(null);
writer.write("3 ", true);
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 \"\r\n", data);
}
示例13: 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);
}
示例14: test132
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void test132() 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.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\"\r\n", data);
}
示例15: Test174
import com.csvreader.CsvWriter; //导入依赖的package包/类
@Test
public void Test174() throws IOException {
// verifies that data is eventually automatically flushed
CsvWriter writer = new CsvWriter("temp.csv");
for (int i = 0; i < 10000; i++)
{
writer.write("stuff");
writer.endRecord();
}
CsvReader reader = new CsvReader("temp.csv");
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("stuff", reader.get(0));
writer.close();
reader.close();
new File("temp.csv").delete();
}