本文整理汇总了Java中com.csvreader.CsvWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter.close方法的具体用法?Java CsvWriter.close怎么用?Java CsvWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例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: 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: 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: 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);
}
示例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: 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();
}
示例10: delimitedExport
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
private static void delimitedExport(CharRecord rec, String filename, char delimiter) throws IOException {
Collection c = rec.getRecords(false);
CsvWriter csvOutput = new CsvWriter(filename, delimiter, Charset.forName("UTF-8"));
for (Iterator iterator = c.iterator(); iterator.hasNext();) {
Record record = (Record) iterator.next();
csvOutput.write(record.getPinyin());
csvOutput.write(record.getChars());
csvOutput.write(record.getTrad());
csvOutput.write(record.getEnglish());
csvOutput.write(record.getBook());
csvOutput.write(record.getChapter());
csvOutput.endRecord();
}
csvOutput.close();
}
示例11: createCSVFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* @param string
* @param header
* @return
*/
private void createCSVFile(File file, List<String> header) {
try {
CsvWriter csv = new CsvWriter(new FileWriter(file), ',');
String[] finalHeaders = new String[header.size()];
int pos = 0;
for (String column : header) {
finalHeaders[pos++] = column;
}
csv.writeRecord(finalHeaders);
csv.close();
} catch (IOException e) {
logger.severe(e.getMessage());
System.exit(1);
}
}
示例12: 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);
}
}
示例13: WriteToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
public void WriteToFile(List<Data> input, String path){
try {
CsvWriter csvOutput = new CsvWriter(new FileWriter("test", false), ',');
int size = input.size();
int start = 0;
for (; start < size; start++) {
Data onerow = input.get(start);
String[] content = onerow.toString().split("\t");
for (String piece : content) {
csvOutput.write(piece);
}
csvOutput.endRecord();
}
csvOutput.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: saveRawFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
private void saveRawFile(String outputFile, String[] lines,
boolean withTitle) {
boolean alreadyExists = new File(outputFile).exists();
try {
CsvWriter csvOutput = new CsvWriter(
new FileWriter(outputFile, true), ',');
int size = lines.length;
int start = 0;
if (!withTitle)
start = 1;
if (alreadyExists) {
start = 1;
}
for (; start < size; start++) {
String line = lines[start];
csvOutput.write(line);
csvOutput.endRecord();
}
csvOutput.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: writeToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
protected void writeToFile(final List<ExportEntry> csvEntries) throws IOException {
FileOutputStream fileOutputStream = getFileOutputStream();
CsvWriter cwriter = new CsvWriter(fileOutputStream, VaultCsvEntry.CSV_DELIMITER, Charset.forName("UTF-8"));
cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
for (ExportEntry item : csvEntries) {
cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
}
cwriter.flush();
cwriter.close();
}