本文整理汇总了Java中com.csvreader.CsvWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter.write方法的具体用法?Java CsvWriter.write怎么用?Java CsvWriter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.write方法的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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();
}
示例9: 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();
}
示例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: 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);
}
示例12: 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);
}
示例13: writeObservationList
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
protected long writeObservationList(List<ObservationState> states) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/tab-separated-values");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
OutputStreamWriter out = new OutputStreamWriter(bc, "US-ASCII");
CsvWriter writer = new CsvWriter(out, '\t');
for (ObservationState state : states) {
writer.write(state.getURI().getCollection());
writer.write(state.getURI().getObservationID());
if (state.maxLastModified != null) {
writer.write(df.format(state.maxLastModified));
} else {
writer.write("");
}
if (state.accMetaChecksum != null) {
writer.write(state.accMetaChecksum.toASCIIString());
} else {
writer.write("");
}
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}
示例14: writeDeleted
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
private long writeDeleted(List<DeletedObservation> dels) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/tab-separated-values");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
OutputStreamWriter out = new OutputStreamWriter(bc, "US-ASCII");
CsvWriter writer = new CsvWriter(out, '\t');
for (DeletedObservation ddo : dels) {
writer.write(ddo.getID().toString());
writer.write(ddo.getURI().getCollection());
writer.write(ddo.getURI().getObservationID());
if (ddo.getLastModified() != null) {
writer.write(df.format(ddo.getLastModified()));
} else {
writer.write("");
}
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}
示例15: writeObservationList
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Override
protected long writeObservationList(List<ObservationState> states) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/csv");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
CsvWriter writer = new CsvWriter(bc, ',', Charset.defaultCharset());
for (ObservationState state : states) {
writer.write(state.getURI().getObservationID());
writer.write(df.format(state.maxLastModified));
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}